Da tvrtok 09 Februr 2006 12:48 Une bvue napsal:
> 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 ?

I thought YAML does deep serialization? It should load this automatically.

What do you mean by Preferences including Themes? If you mean instances of 
Theme are instance variables of Preferences, or are stored in an Array in 
Preferences, you shouldn't need to repopulate anything.

I didn't quite understand the intent of your code, but it looks like you're 
doing copies of themes from o.themes_list to another Array @themes_list... 
Why can't you keep them in the original object "o" and access them from 
there?

David Vallner