From: Jeremy Tregunna Date: 2006-10-17T11:45:20+09:00 Subject: Re: dynamically assigning instance variables (redux) On 06-10-16, at 22:35, Bil Kleb wrote: > Is there a way to dynamically assign instance variables? > > class SomeClass > def initialize(hash) > hash.each do |key,val| > @#{key} = val # Doesn't work > end > end > end Replace: @#{key} = val with: self.instance_variable_set(:@"#{key}", val) > Actually, I'd like the assignment and make them attr_readers too. > > Nearly meta-programming clueless, Not sure on this one, havn't gone too deep into metaprogramming in ruby. -- Jeremy Tregunna jtregunna@blurgle.ca