From: "trans. (T. Onoma)" Date: 2004-11-02T13:17:53+09:00 Subject: Re: Use yaml to store Ruby arrays or hashes in the DB? On Monday 01 November 2004 11:01 pm, James Britt wrote: | trans. (T. Onoma) wrote: | > On Monday 01 November 2004 10:20 pm, James Britt wrote: | > | How can you store Ruby-specific objects (i.e., custom, user-defined | > | classes) in a language-neutral way? | > | > You use YAML. | > | > No really. That's all there it to it. | | The ri data files for 1.8.2 are in YAML. Can I load the following into | a YAML parser in, say, perl or python? How does that language make | sense of it? | | --- !ruby/object:RI::MethodDescription | aliases: [] | block_params: | comment: | - !ruby/struct:SM::Flow::P | body: "Exclusive Or---If obj is nil or | false, returns false; otherwise, returns true." | full_name: FalseClass#^ | is_singleton: false | name: "^" | params: > | false ^ obj => true or false | | nil ^ obj => true or false | | visibility: public You'll have to use types to get rid of the !ruby/object cruft. YAML.add_private_type( 'MehthodDescription' ) { |type, val| RI::MethodDescrition.new( val ) } That'll load it automatically. Note that val is the parsed document (a hash) so your initialize method will either have to deal with that ot you'll need a new constructor method instead. I usually define #initialize_yaml(val) and use that. To output the type correctly use: class RI::MethodDescription def to_yaml_type 'MethodDescription' end end Perl and Python should be able to handle no problem from there. HTH, T. P.S. You can also use a Domain type if you prefer. Form ore info see: http://yaml4r.sourceforge.net/doc/