From: "Jan E." Date: 2012-04-11T11:56:05+09:00 Subject: Re: A Beginner's Question about Metaprogramming Phil Stone wrote in post #1055921: > Thanks, but what does this whole line mean?: > > def self.metaclass; class << self; self; end; end > > If I am correct, this is defining a Class method named metaclass, which > has a method named self...? Please elaborate. No, "self" is not a method, it's a keyword, which refers to the current object (many other languages use "this" instead). The metaclass method returns the eigenclass (aka meta class aka singleton class) of the Creature class. It does this by opening the eigenclass and using the "self" keyword inside the class body. The value of self (the eigenclass) then becomes the value of the whole class expression. class << self # open the eigenclass of self (self is the Creature class) self # in this context, self refers to the eigenclass end # the value of this expression is the value of self This is a pretty common trick. However, it isn't needed any longer, because Ruby 1.9 already has the method Object#singleton_class built-in. In fact, you don't even have to get the singleton class. You can simply call Object#define_singleton_method. -- Posted via http://www.ruby-forum.com/.