Vinicius Cubas Brand
2006-Nov-01 17:57 UTC
Serializing - Deserializing a data structure in RoR
Hi. I have a data structure, with arrays and hashes, with several data types
inside. For instance:
{
:conditions => [ ''stand_id = ?'' , 1],
:limit => 10,
:offset => 10
}
I want to serialize this structure in a string, to be stored , then another
day in other session I would like to restore it exactly as it is, for
instance symbols remain symbols, arrays remain arrays, hashes remain hashes
and so on for other data types. How can I do that in Ruby / RoR?
Thanks, Vinicius
--
.----------------------.
| Vinicius Cubas Brand |
| viniciuscb gmail.com |
''----------------------''
http://vinici.us
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
Serializing is called ''Marshalling'' in Ruby. Marshalling is not at all difficult in Ruby, check for example http://ruby-doc.org/core/classes/Marshal.html http://phrogz.net/ProgrammingRuby/ref_m_marshal.html You could also use YAML to do the same, see http://ruby-doc.org/core/classes/YAML.html --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Deirdre Saoirse Moen
2006-Nov-02 00:09 UTC
Re: Serializing - Deserializing a data structure in RoR
On 11/1/06, Vinicius Cubas Brand <viniciuscb-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi. I have a data structure, with arrays and hashes, with several data types > inside. For instance: > > { > :conditions => [ ''stand_id = ?'' , 1], > :limit => 10, > :offset => 10 > } > > I want to serialize this structure in a string, to be stored , then another > day in other session I would like to restore it exactly as it is, for > instance symbols remain symbols, arrays remain arrays, hashes remain hashes > and so on for other data types. How can I do that in Ruby / RoR?Let''s say you want to put this in myobject.foo. myobject.foo = s.to_yaml Pretty easy. Now you''ve retrieved myobject from the database and you want to load s with the stuff that''s serialized in foo. s = YAML::load(myobject.foo) -- _Deirdre http://deirdre.net/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---