Jan-Erik R.
3/8/2009 7:35:00 PM
Rg Rg schrieb:
> Michael Satterwhite wrote:
>> Sharagoz -- wrote:
>>> Is this what you're looking for?
>>>
>>> 1.upto(8) do |i|
>>> box = eval("pauseBox" + i.to_s)
>>> #do stuff with box
>>> end
>> Exactly. Thanks ... I forgot about eval.
>>
>> Appreciate it much.
>> ---Michael
>
> Would it be possible to do the same thing, but generating the variable
> name?
> i.e.
> 1.upto(8) do |i|
> "pauseBox" + i.to_s = i + 1
> #do stuff with box
> end
>
> This don't work
hm....if you have several variables with names like pauseBox1,
pauseBox2, you did something wrong. For this Array exists.
If this is not an Option there are several other ways (const_get,
instance_variable_get, ...)