Is there any standard package to dump to ruby data structures

Is there any standard package to dump ruby data structures into a
string/stream? which can be eval'd back in ruby script. something like
perl's Data::Dumper?

You may want to look at YAML or Marshall; they are not quite what
you're describing, but may fill the need you're thinking about.

I don't know of anything that outputs code for eval.

Eivind.

···

On Fri, Apr 4, 2008 at 1:10 PM, adm <avinash.magar@gmail.com> wrote:

Is there any standard package to dump ruby data structures into a
string/stream? which can be eval'd back in ruby script. something like
perl's Data::Dumper?

Marshal - faster; shorter binary data
YAML - slower, human readable/editable data

···

On Fri, Apr 4, 2008 at 1:10 PM, adm <avinash.magar@gmail.com> wrote:

Is there any standard package to dump ruby data structures into a
string/stream? which can be eval'd back in ruby script. something like
perl's Data::Dumper?

You could use Marshal
see :
    Marshal.dump
&
    Marshal.load

adm wrote:

···

Is there any standard package to dump ruby data structures into a
string/stream? which can be eval'd back in ruby script. something like
perl's Data::Dumper?

adm wrote:

Is there any standard package to dump ruby data structures into a
string/stream? which can be eval'd back in ruby script. something like
perl's Data::Dumper?

In addition to the other suggestions of Marshal and YAML you can also
use 'pp' on data objects.

  irb(main):002:0> require 'pp'
  => true
  irb(main):003:0> pp x
  "foo"
  irb(main):007:0> pp y
  [1, nil, 3]
  irb(main):012:0> pp z
  {"three"=>3, "two"=>2, "one"=>1}

Bob

adm wrote:

Is there any standard package to dump ruby data structures into a
string/stream? which can be eval'd back in ruby script. something like
perl's Data::Dumper?

Probably, the other answers are more helpful, but if you really want to dump to ruby code that can be eval-ed back to get the objects, there is amarshal:

http://www.a-k-r.org/amarshal

···

--
       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407