From: Vivek Date: 2006-01-25T00:46:31+09:00 Subject: Re: "self.class" vs. "(class << self; self; end)" > In the second example You reopen an eigenclass (which is a singleton > instance of class object) and then define a method for it. What exactly do you mean by eigenclass? is it the same as an anonymous class created by class< > Ruby returns last evaluated statement which in this case '(class << > self; self; end)' is eigenclass... > > The eigneclass pattern (a metaclass) is a method of creating single > class instances per instances of them. (I dont know if I made it clear :) ) Is this correct.In the first method,we add a method to the class and so all objects of this class instantiated from the point after calling test1 will have the method 'foo' .What about objects created before this point? But in the second case ,only the object on which we call test1 will have the method foo defined. > > > consider: > > def test1() > msg = 'bar' > self.class.class_eval do > p self > define_method('foo') { msg } > end > end > > > def test2 > msg = 'baz' > (class << self; self; end).class_eval do > p self > define_method('foo') { msg } > end > end > > > test1 > p foo > > test2 > p foo > > output: > > Object > "bar" > #> > "baz" > > lopex