Flethuseo
Flethuseo

Reputation: 6189

Copying a class object

I have an instance object named layers which is an array of 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?

Upvotes: 0

Views: 136

Answers (1)

Chuck
Chuck

Reputation: 237010

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.

Upvotes: 1

Related Questions