# Saving objects to files

**URL:** <https://www.ruby-forum.com/t/saving-objects-to-files/100597>\
**Category:** Ruby\
**Created:** [July 30, 2006, 6:01pm UTC](https://www.ruby-forum.com/t/saving-objects-to-files/100597 "2006-07-30T18:01:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![the-companion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47774/32.png) [@the-companion](https://www.ruby-forum.com/u/the-companion)\
**Post date:** [July 30, 2006, 6:01pm UTC](https://www.ruby-forum.com/t/saving-objects-to-files/100597/1 "2006-07-30T18:01:59Z")

</div>

Is there a way to save an object (say, a hash map) to a file, and then  
retrieve the object from the file?

Thanks

---

<div class="post-metadata">

**Author:** ![the-companion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47774/32.png) [@the-companion](https://www.ruby-forum.com/u/the-companion)\
**Post date:** [July 30, 2006, 6:17pm UTC](https://www.ruby-forum.com/t/saving-objects-to-files/100597/2 "2006-07-30T18:17:30Z")

</div>

On 30/07/06, Ell Q. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is there a way to save an object (say, a hash map) to a file, and then  
> retrieve the object from the file?
> 
> Thanks

[http://www.ruby-doc.org/core/classes/Marshal.html](http://www.ruby-doc.org/core/classes/Marshal.html)

---

<div class="post-metadata">

**Author:** ![the-companion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47774/32.png) [@the-companion](https://www.ruby-forum.com/u/the-companion)\
**Post date:** [July 30, 2006, 6:20pm UTC](https://www.ruby-forum.com/t/saving-objects-to-files/100597/3 "2006-07-30T18:20:57Z")

</div>

Ell Q. wrote:

> Is there a way to save an object (say, a hash map) to a file, and then  
> retrieve the object from the file?

Marshal and YAML are the easiest. Depending on your need you might want  
to use PStore or a database. HTH

Kind regards

```
robert
```
