From: Joel VanderWerf Date: 2006-02-10T05:44:22+09:00 Subject: Re: yaml object de-serialisation Une b�vue wrote: > i've a class "Preferences" > which includes other classes for example "Theme" > > i save an instance of "Preferences" by writing self.to_yaml into a file. > > obviously, i want to retrive this instance back by : > o=YAML::load(File.open("#{PREFS_FILE}")) > > PREFS_FILE being the preceedingly saved one. > > what's the best way to "re-populate" my classes ? > > for the time being i'm doing : > > o.themes_list.each { |theme| > t=Theme.new(theme.label) > t.nb_cols_list=theme.nb_cols_list > @themes_list << t > } > [...] > @theme_label=o.theme_label > @nb_cols=o.nb_cols > > > does exist a more direct way to do the samething ? This may be helpful, or at least interesting: http://raa.ruby-lang.org/project/preferences/ http://redshift.sourceforge.net/preferences/doc/index.html It's a way of automating the configuration of objects from a hierarchical hash stored in a YAML file. It works with existing accessors, so it's very easy to use with a GUI toolkit. See examples/foursplit-prefs.rb for a version of the FXRuby foursplit.rb example, but using Preferences. -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407