I’m trying to find out if is possible to serialize a class object, with
their own instance variables, something like this:
class Foo
@x = 10
@y = 20
end
Then I went to Dave T. book: Programming Ruby 1.9 to the section
which talk about Marshal. It say literaly:
“Some objects cannot be dumped: if the objects to be dumped include
bindings, procedure or method objects, instances of class IO, or
singleton objects, or if you try to dump anonymous classes or modules, a
TypeError will be raised.”
So obvious Foo is not a singleton object, is a class object. I’ve tried
to Marshal this class in the common way and succed, no TypeError arised.
But when I restore, no clue about his own instance variables. I wonder
what does mean Dave when he say “anonymous classes or modules”…
I’ve opened a topic short time ago related with this, asking about
marshaling classes and his class variables, I surrendered trying to save
classes with his class variables but what about his own instance
variables, It is not a common object? I just can’t? What is the option
to serialize this kind of data? Do I have to appeal to metaprogramming?
Thank you guys.