From: Manoj Kumar Date: 2010-06-29T10:58:15+09:00 Subject: Re: Singleton class in Ruby Jes炭s Gabriel y Gal叩n wrote: > On Mon, Jun 28, 2010 at 7:01 AM, Manoj Kumar > wrote: >>>> end >>> B.D. >> available in singleton.instance_methods. >> >> Why it is like this? Any special reason for this? > > Because methods returns the list of methods that are accessible for > the object. In the case of the singleton class, it's the instance of > the class (the object) for which you call the method "test". It's the > same thing as with regular classes: > > irb(main):001:0> class A > irb(main):002:1> def test > irb(main):003:2> "test" > irb(main):004:2> end > irb(main):005:1> end > => nil > irb(main):006:0> A.methods.grep(/test/) > => [] > irb(main):007:0> A.instance_methods.grep(/test/) > => ["test"] > irb(main):008:0> a = A.new > => # > irb(main):009:0> a.methods.grep(/test/) > => ["test"] > > Jesus. Thanks Jesus, manoj -- Posted via http://www.ruby-forum.com/.