How do you save the contents of an object?

S

Steve Quezadas

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

Timothy Hunter

Steve said:
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
 
I

Ilan Berci

Steve said:
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\n"
 
F

Farrel Lifson

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\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
 
G

Gustav Paul

Steve said:
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-objects-to-disc

Hope it helps!
Gustav Paul
(e-mail address removed)
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top