Jesús Gabriel y Galán wrote: > On Fri, Jun 25, 2010 at 6:11 AM, Manoj Kumar <manojs.nitt / gmail.com> > wrote: >> Can we see the singleton class as object in ruby. > > Like this? > > irb(main):001:0> o = Object.new > => #<Object:0xb743f3fc> > irb(main):002:0> singleton = class << o; self; end > => #<Class:#<Object:0xb743f3fc>> > irb(main):003:0> singleton > => #<Class:#<Object:0xb743f3fc>> > 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 #<Class:#<Object:0xb743f3fc>> the singleton class object for object o? -- Posted via http://www.ruby-forum.com/.