From: David Masover Date: 2009-03-05T16:39:02+09:00 Subject: Re: with YAML can I retrieve the class type back??? Greg Hauptmann wrote: > Hi, > If I wanted to persist different Ruby types (e.g. float, BigDecimal, > integer, string) to a database based table (e.g. column names KEY and > VALUE), if I use the "to_yaml" method to serialize their values and store > them as strings, what's the easiest way to retrieve them back to a Ruby > variable such that they are of the original type (i.e. not a YAML type). If you're using Rails, there's a helper built in. For example, if your column named "value" is the object you want stored that way: class Whatever < ActiveRecord::Base serialize :value ... end If you want to do it yourself, use YAML.load: serialized = my_object.to_yaml object = YAML.load(serialized) I have no idea if this is safe for untrusted data -- I suspect it's not. So, use this with your own databases, not with random web services, at least without putting some thought into it.