From: Manoj Kumar Date: 2010-06-27T22:43:32+09:00 Subject: Re: Singleton class in Ruby Jes炭s Gabriel y Gal叩n wrote: > On Fri, Jun 25, 2010 at 6:11 AM, Manoj Kumar > wrote: >> Can we see the singleton class as object in ruby. > > Like this? > > irb(main):001:0> o = Object.new > => # > irb(main):002:0> singleton = class << o; self; end > => #> > irb(main):003:0> singleton > => #> > irb(main):004:0> def o.test; "test"; end > => nil > irb(main):008:0> singleton.instance_methods(false) > => ["test"] > > Jesus. As you said class << o; self; end In Rails, there is a method called metaclass which is defined in Object def metaclass class << self self end end is #> the singleton class object for object o? -- Posted via http://www.ruby-forum.com/.