[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Marshalling delegates

elbows

11/20/2003 10:58:00 PM

I can't seem to marshal a delegate. The code below:

class Foo < SimpleDelegate
end

Marshal.dump(Foo.new(nil))

Gives me an error:
TypeError: singleton can't be dumped

The weird thing is that defining _dump or marshal_dump in Foo doesn't
make this problem go away.
Even stranger is that this error suddenly started showing up in code
that used to work... I'm not sure what may haev changed in the interim
(haven't touched the code in a few weeks), except I may have apt-get
updated my ruby installation.

Is there any way I can dump a delegate?

Nathan
2 Answers

matz

11/21/2003 3:30:00 AM

0

Hi,

In message "Marshalling delegates"
on 03/11/21, Nathan Weston <elbows@spamcop.net> writes:

|I can't seem to marshal a delegate. The code below:
|
|class Foo < SimpleDelegate
|end
|
|Marshal.dump(Foo.new(nil))
|
|Gives me an error:
|TypeError: singleton can't be dumped
|
|The weird thing is that defining _dump or marshal_dump in Foo doesn't
|make this problem go away.

It's a bug in 1.8.0. Soon to be fixed. Thank you.

matz.


elbows

11/28/2003 11:04:00 PM

0

After digging around a bit in the delegate source, I fixed the problem
like this:

class MarshalDelegator < SimpleDelegator
alias :make_methods :initialize

def marshal_dump
return @obj
end

def marshal_load(obj)
initialize(obj)
end
end

To marshal, the delegator just dumps the object it is delegating for.
To unmarshal, it loads that object, and sets up the wrapper methods by
calling initialize.




matz@ruby-lang.org (Yukihiro Matsumoto) wrote in message news:<1069385366.583829.29360.nullmailer@picachu.netlab.jp>...
> Hi,
>
> In message "Marshalling delegates"
> on 03/11/21, Nathan Weston <elbows@spamcop.net> writes:
>
> |I can't seem to marshal a delegate. The code below:
> |
> |class Foo < SimpleDelegate
> |end
> |
> |Marshal.dump(Foo.new(nil))
> |
> |Gives me an error:
> |TypeError: singleton can't be dumped
> |
> |The weird thing is that defining _dump or marshal_dump in Foo doesn't
> |make this problem go away.
>
> It's a bug in 1.8.0. Soon to be fixed. Thank you.
>
> matz.