So, my goal is to easily save some data to disk for later use. How do you just write and then read the object? Therefore, if I have a simple class
class C attr_accessor :a, :b def initialize(a, b) @a, @b = a, b end end
So, if I create obj from this very fast
obj = C.new("foo", "bar")
Then I can turn this into a kind of id
string = obj.to_s #which returns "<C:0x240dcf8 @a="foo", @b="bar">"
I can finally print this line in a file or something like that. My question is: how do I again include this identifier back in the object? I know that I can independently parse this information and perform the initialization function, which accepts this information, but, of course, the ruby has something built-in to turn it back into an object, right?
source share