From: Stu Date: 2012-04-11T09:09:30+09:00 Subject: Re: A Beginner's Question about Metaprogramming On Tue, Apr 10, 2012 at 6:33 PM, Phil Stone wrote: > I don't understand this code at all, especially the line "def > self.metaclass; class << self; self; end; end". Where do all the names > such as metaclass.instance_eval or class_eval come from? I'm really > confused about this piece of code, and would appreciate some > explanation. Sorry if these questions are rather basic. > > -- > Posted via http://www.ruby-forum.com/. > class << self is the same as def self.method Look at a simpler example: #Initial class definition: class MyClass def hi "hi!!!" end end # Reopened with metaclass self.method style: class MyClass def self.hello "hello" end end # Reopened with metaclass class << self style: class MyClass class << self def goodbye "bye!!!" end end end > MyClass.new.hi => "hi!!!" > MyClass.hello => "hello" > MyClass.goodbye => "bye!!!"