[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How do you save the contents of an object?

Steve Quezadas

10/24/2006 12:17:00 AM

Is there an easy way to save the contents of an object in ruby?

This is hard to google, so I am posting it up. I just need a general
idea (if anyoen has it), you don't have to spell it out for me.

--
Posted via http://www.ruby-....

6 Answers

Tim Hunter

10/24/2006 12:26:00 AM

0

Steve Quezadas wrote:
> Is there an easy way to save the contents of an object in ruby?
>
> This is hard to google, so I am posting it up. I just need a general
> idea (if anyoen has it), you don't have to spell it out for me.
>
>
ri Marshal
ri YAML

Ilan Berci

10/24/2006 2:47:00 PM

0

Steve Quezadas wrote:
> Is there an easy way to save the contents of an object in ruby?
>

As a further aside to saving with yaml, yet another fantastic little
goody that RoR provides is the method .to_yaml() ..

ilan@iberci-pc:~/rails$ script/console
Loading development environment.
>> "sample".to_yaml
=> "--- sample\n"



--
Posted via http://www.ruby-....

Farrel Lifson

10/24/2006 3:00:00 PM

0

On 24/10/06, Ilan Berci <coder68@yahoo.com> wrote:
> Steve Quezadas wrote:
> > Is there an easy way to save the contents of an object in ruby?
> >
>
> As a further aside to saving with yaml, yet another fantastic little
> goody that RoR provides is the method .to_yaml() ..
>
> ilan@iberci-pc:~/rails$ script/console
> Loading development environment.
> >> "sample".to_yaml
> => "--- sample\n"

You don't need RoR for that. Merely including yaml will give objects
the to_yaml method:

irb(main):001:0> require 'yaml'
=> true
irb(main):002:0> puts({"one"=>1,"two"=>2,"three"=>3}.to_yaml)
---
three: 3
two: 2
one: 1
=> nil

Farrel

Gustav - Railist

10/24/2006 3:26:00 PM

0

Steve Quezadas wrote:
> Is there an easy way to save the contents of an object in ruby?
>
> This is hard to google, so I am posting it up. I just need a general
> idea (if anyoen has it), you don't have to spell it out for me.
>
>
I posted an article/tutorial on marshalling objects and saving them to
files last night,
you may want to throw a quick look at it as it sounds applicable to your
question...

http://rails.co.za/articles/2006/10/23/saving-ruby-objec...

Hope it helps!
Gustav Paul
gustav@rails.co.za

guoxianghao@gmail.com

10/25/2006 10:27:00 AM

0

Use YAML you can store/load the content of a Ruby object without any
difficulty.

Please visit YAML.rb at http://yaml4r.source...
The codebook is of great use to give you what is going on:
http://yaml4r.source...cookbook/

Steve Quezadas wrote:
> Is there an easy way to save the contents of an object in ruby?
>
> This is hard to google, so I am posting it up. I just need a general
> idea (if anyoen has it), you don't have to spell it out for me.
>
> --
> Posted via http://www.ruby-....

Jordan Running

10/25/2006 3:27:00 PM

0

The built-in Marshal class is designed for this very thing, and
anecdotal evidence says it's faster than YAML. YAML has the advantage
of being readable to the naked eye, however. Here's a good discussion
on Marshal vs. YAML:

http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb/ruby/ruby-talk/99119?99...


On 10/25/06, guoxianghao@gmail.com <guoxianghao@gmail.com> wrote:
> Use YAML you can store/load the content of a Ruby object without any
> difficulty.
>
> Please visit YAML.rb at http://yaml4r.source...
> The codebook is of great use to give you what is going on:
> http://yaml4r.source...cookbook/
>
> Steve Quezadas wrote:
> > Is there an easy way to save the contents of an object in ruby?
> >
> > This is hard to google, so I am posting it up. I just need a general
> > idea (if anyoen has it), you don't have to spell it out for me.
> >
> > --
> > Posted via http://www.ruby-....
>
>
>