On Mar 13, 2007, at 9:50 AM, Matteo Cavalleri wrote: > I need to create some objects of different (custom) classes, in > different pages of my site, so I made some code that takes an array of > hashes and create the objects. the hashes are like this one: > > h = { :class => Class1, :param1 => 'foo', :param2 => 'bar', etc } > > and basically I do > > object = h[:class].new(h) > > everything works fine as long as the hash is defined inside the source > code. however in some case I need to create the same object in two > different file. to avoid writing the same hashes twice I though about > putting them in a YAML file but this method doesn't work anymore > because > the class name is converted to a string instead of a reference to the > class, using !ruby/object creates the object but all the code > inside the > initialize method seems to be never executed (or the instance > variables > ovverrided after the inzialize method) so my objects don't work, > ClassName.to_yaml returns an error, etc... > > is there a way to do what I want to do? putting the ashes in a file > and > loading them as a source AFAIK creates other problem due to the > sandboxing made by mod_ruby, that's why I tried with yaml. It seems to me this is a fundamental problem with YAML. Even if you were trying to put all the data in one file, I don't believe the YAML spec. addresses writing object references instead of objects. This is especially an issue when your objects have circular references. This caused me to use XML instead of YAML for a recent Java project because the Java XStream library handles serializing and deserializing Java objects that have circular references. If there is a YAML solution to this, I'd love to hear about it!