bachase / gmail.com <bachase / gmail.com> wrote:

> Consider:
> 
> class BigGuy
>    def initialize
>       @favorites = ["a","b","c"]
>    end
> 
>    class << self
>      def display_favs
>       class_eval "p @favorites"
>      end
>    end
> end
> 
> class LittleGuy < BigGuy
>      display_favs
> end
> 
> Why does this display "nil"?  I expected the initialize of BigGuy to
> occur prior to invoking display_favs.  Any other construction I should
> be using to get my desire behavior of the constructor of the base class
> getting called prior to singleton methods called from the child class?

"Initialize" is called when the class is instantiated (i.e. with new).
You are never instantiating this class, so "initialize" is never called.
m.


-- 
matt neuburg, phd = matt / tidbits.com, http://www.tidbits.com/matt/
Tiger - http://www.takecontrolbooks.com/tiger-customizing.html
AppleScript - http://www.amazon.com/gp/product/0596102119
Read TidBITS! It's free and smart. http://www.tidbits.com