From: Robert Dober Date: 2007-07-26T02:43:45+09:00 Subject: Re: Detecting singletons On 7/25/07, Lars Westergren wrote: > Robert Dober skrev: > > On 7/25/07, Lars Westergren wrote: > > well seems you have to use my code then, it depends on a "feature" > > Matz has put deliberately into the implementation of ancestor, > > singletons are not included. > > Does this fit your definition of singleton? > > Not sure.... Your code works good in irb and catches singletons > created as > class << self;self;end; > > there. However, I still got the bug in Rails. OMG Rails, what do they do my Ruby? ;) But I think it is Marshal, are you sure that it is the singleton which causes problems? AFAIK there are other things which make objects not serializable, gotta find some time to look into this... >I have done this- > > marsh = class << Marshal; self; end > marsh.send :alias_method, "old_dump", "dump" > marsh.class_eval< def dump(o); > STDERR.puts \"Problem class is a \" + o.class.name; > STDERR.puts o.inspect; > if o.class.is_singleton?; > puts \"it's a singleton!\"; > else > puts \"not a singleton...\"; > end; > old_dump(o); > end > ENDOFSTRING > > And I get "not a singleton..." immediately followed by the exception. > The "problematic" object I think is the :session hash object, or rather > an object stored inside it. Either I'm looking in the wrong place, or I > need to traverse the object graph examening each object in array/hash. > > Is there a library available for that? > > I wish I could paste the inspect string for you people, but it is > several pages long and contains personal information. hmm maybe you can get us some condensed info, but did you check the RDoc for what could raise the TypeError in dump? Cheers Robert > > Thanks again, > Lars > > -- I always knew that one day Smalltalk would replace Java. I just didn't know it would be called Ruby -- Kent Beck