From: "David A. Black" Date: 2008-12-14T22:23:34+09:00 Subject: Re: singleton methods vs. meta instance methods Hi -- On Sun, 14 Dec 2008, Brian Candler wrote: > Robert Dober wrote: >> But... alas >> you say that a meta.instance_methods returns both instance methods in >> the metaclass plus the instance methods >> of the actual class. I agree, you have shown this, however, :new, >> :allocate & :superclass are instance methods of the metaclass, not of >> the actual class, or are they not? > > I believe that they are instance methods of the actual class "Class". > > irb(main):002:0> Class.instance_methods(false) > => ["allocate", "superclass", "new"] Here's a demo of the consistency from the Class case to the SomeClass case. I'm still not convinced that it's the ideal behavior. $ cat sing.rb class Object def singleton_class; class << self; self; end; end end class A def x; end end an_a = A.new def an_a.y; end p A.instance_methods(false) p an_a.singleton_class.instance_methods(false) $ ruby sing.rb ["x"] ["y", "x"] $ ruby -pe 'gsub(/A/,"Class")' sing.rb | ruby - ["allocate", "superclass", "new", "x"] ["y", "allocate", "superclass", "new", "x"] David -- Rails training from David A. Black and Ruby Power and Light: INTRO TO RAILS (Jan 12-15), Fort Lauderdale, FL See http://www.rubypal.com for details Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)