Writing objects to file?

Discussion in 'Ruby' started by Nebs Petrovic, Aug 6, 2008.

  1. Hey,

    I'm wondering if it's possible to save a group of objects in a file so
    that they are present whenever the application is run.

    Example:
    Let's say we have a class Car and we have a program that let's users add
    a bunch of cars. When the user adds a car it is pushed into an array of
    Cars. I want to be able to save this whole array along with all the
    objects and their variables in tact so that next time the program is run
    all the user data will be there as if they hadn't closed the program.

    I can always come up with my own file formatting and save the individual
    instance variables of the objects and then recreate the objects on load
    but it just seems like there should be an easier way. Maybe dump the
    array memory into a file and then recall it quickly on load?

    Thanks.
    --
    Posted via http://www.ruby-forum.com/.
     
    Nebs Petrovic, Aug 6, 2008
    #1
    1. Advertising

  2. 2008/8/6 Nebs Petrovic <>:
    > I'm wondering if it's possible to save a group of objects in a file so
    > that they are present whenever the application is run.



    Try PStore or Marshal or if you want something human readable and editable YAML

    Farrel
    --
    Aimred - Ruby Development and Consulting
    http://www.aimred.com
     
    Farrel Lifson, Aug 6, 2008
    #2
    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. HNguyen
    Replies:
    4
    Views:
    2,453
    HNguyen
    Dec 21, 2004
  2. Ron Albright

    Writing objects to random file

    Ron Albright, Feb 5, 2004, in forum: Java
    Replies:
    3
    Views:
    412
    Ron Albright
    Feb 5, 2004
  3. Peter Loh
    Replies:
    0
    Views:
    343
    Peter Loh
    Feb 5, 2004
  4. Marcelo

    Writing objects to a file

    Marcelo, Oct 19, 2005, in forum: Java
    Replies:
    6
    Views:
    1,597
    Roedy Green
    Oct 20, 2005
  5. 7stud
    Replies:
    11
    Views:
    750
    Dennis Lee Bieber
    Mar 20, 2007
Loading...

Share This Page