Module, Class, attr_accessor help?
-
I see attr_accessor as being listed under the module class, are there any pitfalls of using it in a class like this:
module AWESOME_MODULE class AWESOME_MODULE;;Cool_class attr_accessor(;color) end end class_object = AWESOME_MODULE;;Cool_class.new class_object.color= "red"I would like to do that, is it considered standard operating procedure? Or is that bad in any way? I was a little confused by the attr_accessor being a method of the module class, instead of the Class class (or something like that).
So, any thoughts on this? Good, bad, ugly? Thanks,
Chris
-
Yes it's fine and also standard ops.
class Class is a subclass of class Module, so inherits the attr_... methods.
The reason they are defined in class Module is so they can be written as Mixin-Modules, that are mixed into classes using include() and extend().
-
Awesome, thanks Dan!
-
I do it that way all the time.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement