From: timr Date: 2011-01-05T06:00:20+09:00 Subject: Re: Is singleton class of an object already created? Could you simply count singleton_methods? If singleton_methods returns an empty array, no singleton_class is present. Could easily add that method to the object class and call it on anything you wanted. But this strategy equates an empty singlton_method query with not having a singleton_class. I am not sure that is exactly correct. Though practically speaking, it seems equivalent to me. Tim class Object def singleton_class? self.singleton_methods.length == 0 ? false : true end end a = '' p a.singleton_class? => false def a.singleton_method_for_a end p a.singleton_class? => true On Jan 4, 9:28 am, Samnang Chhun wrote: > Anurag Priyam wrote in post #972264: > I guess that a singleton class always exists for > > > an object, whether a singleton method for that object exists or not. > > Sure, singleton class always be there, and it inserted in the > inheritance chain before the objects "real" class when the first we need > it. But I would like to generate a diagram of an object's ancestors, if > the object has used singleton class, then it will show in diagram, but > it doesn't if object hasn't used singleton class yet. > > -- > Posted viahttp://www.ruby-forum.com/.