From: Samantha Atkins Date: 2001-06-11T05:46:07+09:00 Subject: [ruby-talk:16394] Re: other ways to create class instance? ts wrote: > > > class A > attr_accessor :foo, :bar, :baz > def initialize(hash) > hash.each do |k, v| > eval "self.#{k}= #{v}" > end > end > end > > a = A.new "foo" => 12, "bar" => 24 > > The problem with this is that I want to be able to transparently persist and recreate any type of object, not just those that specially define the initialize. One hack I did was stuffing in some code like: class A # sometime when we need to reconstruct instance alias old_initialize initialize def initialize(*x) if (x[0].type == SpecialSavedState) x[0].copyInto(self) else old_initialize(*x) end end This sort of worked when done by hand but did not work when I tried to make it a module to use to extend the class. - samantha