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.
精彩评论