开发者

Copying a class object

I have an instance object named layers which is an array o开发者_StackOverflowf Layer objects.

I try the following, and I get an error saying that I'm trying to dump a class method:

@best_copy = Marshal.load(Marshal.dump(@layers))

TypeError: no marshal_dump is defined for class Method

How do I make it so that it isn't trying to save the attr_accessor, but the actual object?


It looks like one or more of your Layers has an instance variable that's a Method. Does that sound right? Marshal sends an object marshal_dump to get the data for marshaling, and in turn the object's attributes also get marshal_dump to get their data. Methods cannot be marshaled, so when the process gets to that part of object, it gets hung up trying to marshal your method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜