How do you save the contents of an object?

Discussion in 'Ruby' started by Steve Quezadas, Oct 24, 2006.

  1. 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-forum.com/.
     
    Steve Quezadas, Oct 24, 2006
    #1
    1. Advertising

  2. 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
     
    Timothy Hunter, Oct 24, 2006
    #2
    1. Advertising

  3. Steve Quezadas

    Ilan Berci Guest

    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-forum.com/.
     
    Ilan Berci, Oct 24, 2006
    #3
  4. On 24/10/06, Ilan Berci <> 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
     
    Farrel Lifson, Oct 24, 2006
    #4
  5. Steve Quezadas

    Gustav Paul Guest

    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-objects-to-disc

    Hope it helps!
    Gustav Paul
     
    Gustav Paul, Oct 24, 2006
    #5
  6. Steve Quezadas

    Guest

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

    Please visit YAML.rb at http://yaml4r.sourceforge.net/
    The codebook is of great use to give you what is going on:
    http://yaml4r.sourceforge.net/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-forum.com/.
     
    , Oct 25, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas Dodds

    Re: Save Datagrid contents to DataSet

    Thomas Dodds, Sep 2, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,859
    Thomas Dodds
    Sep 3, 2004
  2. user
    Replies:
    1
    Views:
    768
    Bruce Barker
    Apr 4, 2005
  3. Don Adams
    Replies:
    1
    Views:
    603
    Martin Honnen
    Mar 5, 2004
  4. Kamarulnizam Rahim
    Replies:
    4
    Views:
    223
    Robert Klemme
    Jan 28, 2011
  5. Replies:
    0
    Views:
    196
Loading...

Share This Page