From: Brian Candler Date: 2008-12-14T20:16:43+09:00 Subject: Re: singleton methods vs. meta instance methods Robert Dober wrote: > On Sat, Dec 13, 2008 at 10:50 PM, Brian Candler > wrote: >> Robert Dober wrote: >>> I could however not see the difference between A and Object, can you >>> explain please? >> >> The OP used an *instance* of class Object, not Object itself, and >> compared it with class A, which is an instance of class Class. > Brian I referred to exactly the same thing you do in your next post, > just do a %s/Object/String/g. Maybe I overlooked something - all these classes and metaclasses can get pretty confusing :-) I was comparing the part of your code where you wrote: def Object.answer; 42 end with the OP's which had: obj = Object.new def obj.foobar; end > No really I feel up to here we are just fine, the problem starts when > we define something in the metaclass and > see it in the singleton class I'm not sure what the distinction is you're trying to make between metaclass and singleton class. I believe they are two names for the same thing. The OP was trying to demonstrate that "an object's singleton methods are defined as the instance methods of that object's meta/singleton class" This was demonstrated successfully, given the additional info that metaclass.instance_methods(false) returns both the instance methods in the metaclass plus the instance methods of the actual class. However, obj.singleton_methods returns only the instance methods in obj.metaclass. At least, that's how I understand it at the moment - I am happy to be corrected if this is wrong. -- Posted via http://www.ruby-forum.com/.