From: blaine Date: 2007-07-25T23:06:18+09:00 Subject: Re: Creating instance variables while looping over a hash 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 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