On Apr 3, 2005, at 4:33 PM, Douglas Livingstone wrote:

> Why does this work:
>
>  class ComplexObject
>     attr_accessor :colour
>     def initialize  # :yield: c
>         ComplexObject.module_eval "undef_method :colour="
>     end	
>  end
>
> But this doesn't?
>
>  class ComplexObject
>     attr_accessor :colour
>     def initialize  # :yield: c
>         self.module_eval "undef_method :colour="
>     end	
>  end
>
> (btw, I know about attr_reader, I'm just looking for ways around the
> "disadvantages" for "Initializing complex objects" at
> http://www.rubygarden.org/ruby?RubyIdioms )
>
> I assumed that self == ComplexObject, but obviously not... why is that?

When initialize() gets called, "self" will be setup to point to the 
current object, as is always true with Ruby instance methods.  If you 
want to fetch the object's class, without hardcoding it, use 
"self.class..."

Hope that helps.

James Edward Gray II