Is there any standard package to dump to ruby data structures

A

adm

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?
 
E

Eivind Eklund

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.
 
J

Jano Svitok

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
 
B

Bob Proulx

adm said:
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
 
J

Joel VanderWerf

adm said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top