Hi
Is it possible to write a ruby object (like a hash for example) to a
file, and then read it and use it accordingly ?
Thanks,
Radu S.
Hi
Is it possible to write a ruby object (like a hash for example) to a
file, and then read it and use it accordingly ?
Thanks,
Radu S.
Radu S. wrote:
Hi
Is it possible to write a ruby object (like a hash for example) to a
file, and then read it and use it accordingly ?Thanks,
Radu S.
Yes, please see Marshal[1] and YAML[2].
-Justin
[1]module Marshal - RDoc Documentation
[2]http://ruby-doc.org/stdlib/libdoc/yaml/rdoc/index.html
Radu S. wrote:
Hi
Is it possible to write a ruby object (like a hash for example) to a
file, and then read it and use it accordingly ?Thanks,
Radu S.
You can either use Marshal or yaml.
Look up Marshal at RDoc Documentation
Look up yaml at RDoc Documentation
Let me followup:
When to use Marshal, when to use yaml?
Does one of the two have a big advantage over the other?
On Aug 23, 2006, at 9:14 PM, Marc H. wrote:
Let me followup:
When to use Marshal, when to use yaml?
Does one of the two have a big advantage over the other?
Marshal is C pretty fast, but it writes binary files that are not
human readable. YAML is plain text, but not as zippy.
Hope that helps.
James Edward G. II
Le 24 août 2006 à 04:20, James Edward G. II a écrit :
On Aug 23, 2006, at 9:14 PM, Marc H. wrote:
Let me followup:
When to use Marshal, when to use yaml?
Does one of the two have a big advantage over the other?Marshal is C pretty fast, but it writes binary files that are not
human readable. YAML is plain text, but not as zippy.
And Marshal is not guaranteed to produce files compatible between
different versions of Ruby, while YAML is.
Fred
Marc H. wrote:
Let me followup:
When to use Marshal, when to use yaml?
Does one of the two have a big advantage over the other?
YAML is human readable/editable.
Marshal is more compact.
That’s about it.
Hal
F. Senault wrote:
And Marshal is not guaranteed to produce files compatible between
different versions of Ruby, while YAML is.
-And- the YAML format is actually an open specification, so you get the
added value of being able to read the same file in other programming
languages - I have mild doubts there are parsers for whatever Marshal
outputs for anything but Ruby.
David V.
“F. Senault” [email protected] writes:
human readable. YAML is plain text, but not as zippy.
And Marshal is not guaranteed to produce files compatible between
different versions of Ruby, while YAML is.
Ironically, history says a different thing.
Christian N. wrote:
“F. Senault” [email protected] writes:
human readable. YAML is plain text, but not as zippy.
And Marshal is not guaranteed to produce files compatible between
different versions of Ruby, while YAML is.Ironically, history says a different thing.
Just because something has always been compatible doesn’t mean it always
will be. Since YAML is an open spec, and Ruby follows that spec, it is
guaranteed. Nobody makes any guarantees about Marshal. (It isn’t
likely to change without good reason, I’m sure, but that’s not a
guarantee.)
William C. [email protected] writes:
Just because something has always been compatible doesn’t mean it always
will be. Since YAML is an open spec, and Ruby follows that spec, it is
guaranteed. Nobody makes any guarantees about Marshal. (It isn’t
likely to change without good reason, I’m sure, but that’s not a
guarantee.)
I was refering to a Ruby version that generated YAML not readable in
other versions due to a missing header or something.
I don’t know when Marshal changed the last time… I can’t find a
mention of changing MAJOR in the CVS history, and MINOR changes (I see
only one) can be read with later versions.
I’d use some kind of plain-text storage (including YAML) for long-term
storage of important data. Marshal would be fine for storing HTTP
sessions, e.g. (And RI too… :^))
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs