I would expect the generated class to be called “GreenDuck”, and to be
defined within the “Green” class.
The problem is that no matter what I do, the dynamically referenced
class name is always just “Class”.
Because what you have is a class method, self is the class that
acts_as_duck is being called on, ie self == Green, and so self.name
will be ‘Green’. self.class is asking ruby what the class of Green is,
and since classes are of class Class you end up with the result you
had.
I would expect the generated class to be called “GreenDuck”, and to be
defined within the “Green” class.
The problem is that no matter what I do, the dynamically referenced
class name is always just “Class”.
Because what you have is a class method, self is the class that
acts_as_duck is being called on, ie self == Green, and so self.name
will be ‘Green’. self.class is asking ruby what the class of Green is,
and since classes are of class Class you end up with the result you
had.
Fred
Ahh. Understood. Thanks for clarifying Fred.
-Chris
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.