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?

On Fri, Apr 4, 2008 at 1:10 PM, adm [email protected] 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 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 [email protected] 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

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

On Apr 4, 4:24 pm, Jano S. [email protected] wrote:

On Fri, Apr 4, 2008 at 1:10 PM, adm [email protected] 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

Yes, I can use Marshal.
Thank you guys.

adm wrote:

On Apr 4, 4:24 pm, Jano S. [email protected] wrote:

On Fri, Apr 4, 2008 at 1:10 PM, adm [email protected] 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
Ruby-specific format

YAML - slower, human readable/editable data
Language-independent format

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs