From: Vincent Bray Date: 2007-07-25T20:19:18+09:00 Subject: Re: Detecting singletons On 25/07/07, Lars Westergren wrote: > I have a fairly large and complex object graph of Value Objects created > by soap4r and used in a Rails application. The app, which used to work, > now gets > Exception `TypeError' at > /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/transactions.rb:97 > - singleton can't be dumped > all over the place and I have narrowed it down to Marshal.dump being > used by Rails. > > I have aliased Marshal.dump so that I can inspect the objects passed > first, I thought that would be the fastest way to locate the problematic > object. My question is, how do I detect that an object is a singleton? > Should I test with "responds_to?" if the "new" method lacking or that > the "instance" method is there? Or is there an easier way? (first post to this list, so get some salt) Singleton in this case probably means that the object you're trying to marshal has a singleton method defined on it (maybe the wrong term. whatever it's called when you do stuff like "def object.foo; some_foo(); end".) The reason it can't be dumped is likely that dumping the 'data' bits of the object won't save the singleton method(s), so unmarshalling would be incomplete. -- noodl