From: Chris Shea Date: 2008-04-09T07:21:08+09:00 Subject: Re: Marshal and singleton.rb - bug? On Tue, Apr 8, 2008 at 3:19 PM, Eric Hodel wrote: > On Apr 8, 2008, at 10:31 AM, Chris Shea wrote: > > > I was looking over the documentation for singleton.rb (because I want > > to help it), and while I was double-checking assumptions I had, I > > noticed that Marshal.load of a serialized singleton instance didn't > > return the singleton instance, but a new one. I assume that the > > expected behavior is that Marshal.load would be to return the sole > > instance. > > > > I wrote a simple test case here: http://pastie.textmate.org/177309 > > > > There's assert_same which does the #equal? comparison. Good to know. Thanks. > > My installation of Ruby (ruby 1.8.6 (2007-03-13 patchlevel 0) > > [i686-darwin9.1.0]) fails the last two, as does trunk (r15929). > > > > Are my assumptions correct? > > > > In order for this to work as you expect, Marshal would need to replace the > existing instance, which is out of it's scope. It might be possible to > "fix" by overwriting allocate, but that seems dangerous. Marshal shouldn't need to replace the existing instance, just return it. In Singleton::SingletonClassMethods def _load(str) instance end Perhaps by mistake, JRuby 1.1 (at least) passes those tests. Chris