From: "F. Senault" Date: 2007-07-24T07:35:02+09:00 Subject: Re: Variable Generation Le 23 juillet 2007 � 23:19, Ari Brown a �crit : > My current method (which FAILS) is using eval > array.each {|item| eval(item + "=\"#{item}\"") } When the eval is run, you're in the context of the block. If the variable exists beforehand, you can use it. Otherwise, I don't know if it can be done. You can try to make an accessor method, though : [ 'a', 'b', 'c' ].each do |t| eval <<-EOE def #{t} '#{t}' end EOE end puts a puts b On the other hand, you can always use instance variables, with the following code for instance : [ 'a', 'b', 'c' ].each do |t| self.instance_variable_set("@#{t}".to_sym, t) end puts @a puts @b In some contexts, I guess you could also call attr_accessor to generate the accessors, but I can't wrap my mind around it at this hour... :) Fred -- Dogs of war and men of hate With no cause, we don't discriminate Discovery is to be disowned Our currency is flesh and bone Hell opened up and put on sale Gather 'round and haggle For hard cash, we will lie and deceive Even our masters don't know the web we weave (Pink Floyd)