blaine
7/25/2007 2:06:00 PM
Your example really showed me, thank you so much Etienne. You have
really helped me understand it much better by your example.
--
Tim Knight
On Jul 25, 9:32 am, dohzya <doh...@gmail.com> wrote:
> Just an example to explain my mind :
>
> ---
> # some representation of your data
> config = {'config' => {'value1' => 'Something here', 'value2' =>
> 'Something else'}}
>
> class A
> def m config
> config["config"].each { |key, value|
> # attr_accessor key (optional)
> self.class.instance_eval {attr_accessor key.to_s}
> # @key = value
> instance_variable_set "@#{key}", value
> }
> end
> end
>
> # test
> a = A.new
> a.m config
> p a.value2
> ---
>
> you can also specify if you want an attribute readable and/or writable
>
> --
> Etienne Vallette d'Osia