# Is there any standard package to dump to ruby data structures

**URL:** <https://www.ruby-forum.com/t/is-there-any-standard-package-to-dump-to-ruby-data-structures/133856>\
**Category:** Ruby\
**Created:** [April 4, 2008, 1:10pm UTC](https://www.ruby-forum.com/t/is-there-any-standard-package-to-dump-to-ruby-data-structures/133856 "2008-04-04T13:10:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![adm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/6f9a4e/32.png) [@adm](https://www.ruby-forum.com/u/adm)\
**Post date:** [April 4, 2008, 1:10pm UTC](https://www.ruby-forum.com/t/is-there-any-standard-package-to-dump-to-ruby-data-structures/133856/1 "2008-04-04T13:10:57Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![adm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/6f9a4e/32.png) [@adm](https://www.ruby-forum.com/u/adm)\
**Post date:** [April 4, 2008, 1:23pm UTC](https://www.ruby-forum.com/t/is-there-any-standard-package-to-dump-to-ruby-data-structures/133856/2 "2008-04-04T13:23:27Z")

</div>

On Fri, Apr 4, 2008 at 1:10 PM, adm [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![adm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/6f9a4e/32.png) [@adm](https://www.ruby-forum.com/u/adm)\
**Post date:** [April 4, 2008, 1:25pm UTC](https://www.ruby-forum.com/t/is-there-any-standard-package-to-dump-to-ruby-data-structures/133856/3 "2008-04-04T13:25:13Z")

</div>

On Fri, Apr 4, 2008 at 1:10 PM, adm [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![adm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/6f9a4e/32.png) [@adm](https://www.ruby-forum.com/u/adm)\
**Post date:** [April 4, 2008, 1:32pm UTC](https://www.ruby-forum.com/t/is-there-any-standard-package-to-dump-to-ruby-data-structures/133856/4 "2008-04-04T13:32:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![adm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/6f9a4e/32.png) [@adm](https://www.ruby-forum.com/u/adm)\
**Post date:** [April 4, 2008, 3:46pm UTC](https://www.ruby-forum.com/t/is-there-any-standard-package-to-dump-to-ruby-data-structures/133856/5 "2008-04-04T15:46:07Z")

</div>

On Apr 4, 4:24 pm, Jano S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Fri, Apr 4, 2008 at 1:10 PM, adm [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![adm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/6f9a4e/32.png) [@adm](https://www.ruby-forum.com/u/adm)\
**Post date:** [April 4, 2008, 5:18pm UTC](https://www.ruby-forum.com/t/is-there-any-standard-package-to-dump-to-ruby-data-structures/133856/6 "2008-04-04T17:18:25Z")

</div>

adm wrote:

> On Apr 4, 4:24 pm, Jano S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > On Fri, Apr 4, 2008 at 1:10 PM, adm [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![adm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/6f9a4e/32.png) [@adm](https://www.ruby-forum.com/u/adm)\
**Post date:** [April 4, 2008, 6:18pm UTC](https://www.ruby-forum.com/t/is-there-any-standard-package-to-dump-to-ruby-data-structures/133856/7 "2008-04-04T18:18:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![adm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/6f9a4e/32.png) [@adm](https://www.ruby-forum.com/u/adm)\
**Post date:** [April 4, 2008, 8:57pm UTC](https://www.ruby-forum.com/t/is-there-any-standard-package-to-dump-to-ruby-data-structures/133856/8 "2008-04-04T20:57:05Z")

</div>

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](http://www.a-k-r.org/amarshal)
