From: Stu Date: 2012-04-11T11:33:46+09:00 Subject: Re: A Beginner's Question about Metaprogramming On Tue, Apr 10, 2012 at 7:15 PM, Phil Stone wrote: > 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. > > -- > Posted via http://www.ruby-forum.com/. > It returns self which in this case is a singleton class called metaclass which also is a metaclass. It would confuse me also. class << self is shorthand for opening up the current class. to make things worse you can open up metaclasses inside metaclasses. Look at my example and run these commands: MyClass.singleton_class MyClass.singleton_methods Basically these are just hidden classes which can be used for exercising the code. If your really interested in the subject I found metaprogramming ruby (book) to be a very interesting read.