[LRUG] Best way to serialise a Ruby object?

Riccardo Tacconi rtacconi at gmail.com
Thu Jul 14 02:28:55 PDT 2011


Hi,

I do not know if you use Ruby or Rails, but for instance ActiveRecord uses
serialize method, which is YAML stored in  the DB:

class User < ActiveRecord::Base
  serialize :preferences
end



On 14 July 2011 11:19, Jonathan del Strother <maillist at steelskies.com>wrote:

> Marshal.dump would be the obvious choice.  Just make sure you're
> either storing it as binary or converting to base64 first, to avoid
> interesting encoding/decoding problems in mysql.
>
> On 14 July 2011 10:11, Andrew Stewart <boss at airbladesoftware.com> wrote:
> > Hola El Rug,
> >
> > What's the best way these days to serialise a Ruby object for storage in
> a SQL database field, and de-serialise it back again?
> >
> > To date I've been using YAML but I've run across a situation where the
> YAML written by Ruby can't be de-serialised again (due, I think, to Sych
> versus Psych).
> >
> > Should I be switching to something other than YAML?
> >
> > Cheers,
> > Andy Stewart
> >
> > -------
> > http://airbladesoftware.com
> > _______________________________________________
> > Chat mailing list
> > Chat at lists.lrug.org
> > http://lists.lrug.org/listinfo.cgi/chat-lrug.org
> >
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>



-- 
Riccardo Tacconi
Ruby on Rails and PHP development - System Administration
VIRTUELOGIC LIMITED

http://github.com/rtacconi
http://riccardotacconi.blogspot.com
http://twitter.com/rtacconi
http://www.linkedin.com/in/riccardotacconi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20110714/b72bbd7d/attachment.html>


More information about the Chat mailing list