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.
    Steve Quezadas, Oct 24, 2006
    1. Advertisements

  2. ri Marshal
    ri YAML
    Timothy Hunter, Oct 24, 2006
    1. Advertisements

  3. Steve Quezadas

    Ilan Berci Guest

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

    [email protected]:~/rails$ script/console
    Loading development environment.=> "--- sample\n"
    Ilan Berci, Oct 24, 2006
  4. 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 Lifson, Oct 24, 2006
  5. Steve Quezadas

    Gustav Paul Guest

    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

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

    guoxianghao Guest

    guoxianghao, Oct 25, 2006
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.