# Writing objects to file?

**URL:** <https://rubytalk.org/t/writing-objects-to-file/48168>\
**Category:** ruby-talk\
**Created:** [6 August 2008 16:42 UTC](https://rubytalk.org/t/writing-objects-to-file/48168 "2008-08-06T16:42:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nebs\_Petrovic](https://avatars.discourse-cdn.com/v4/letter/n/f4b2a3/32.png) [@Nebs\_Petrovic](https://rubytalk.org/u/Nebs_Petrovic)\
**Post date:** [6 August 2008 16:42 UTC](https://rubytalk.org/t/writing-objects-to-file/48168/1 "2008-08-06T16:42:41Z")

</div>

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/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Farrel\_Lifson](https://avatars.discourse-cdn.com/v4/letter/f/3da27b/32.png) [@Farrel\_Lifson](https://rubytalk.org/u/Farrel_Lifson)\
**Post date:** [6 August 2008 16:53 UTC](https://rubytalk.org/t/writing-objects-to-file/48168/2 "2008-08-06T16:53:22Z")

</div>

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

Farrel

> **···**
>
> 2008/8/6 Nebs Petrovic \<nebs\_man@hotmail.com\>:
> 
> > 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.
> 
> --  
> Aimred - Ruby Development and Consulting
> 
> > **[Aimred - Home - Ruby and Rails Development in Cape Town, South
> Africa](http://www.aimred.com)**
> >
> > Aimred is a specialist Ruby and Ruby on Rails development house and consultancy based in Cape Town, South Africa.
