A
Ari Brown
yes, I mean spontaneously generated variables.
Assume we have an array:
array = %w(yea cool awesome stuff)
Now, I'm looking to make a variable corresponding to the item. so that:
yea = "yea"
cool = "cool"
awesome = "awesome"
stuff = "stuff"
My current method (which FAILS) is using eval
array.each {|item| eval(item + "=\"#{item}\"") }
I tested this with a puts instead of eval, and it comes out exactly
as it should. But when I try to use the variable, I get a
undefined local variable or method
error.
Bwah?
-------------------------------------------------------|
~ Ari
crap my sig won't fit
Assume we have an array:
array = %w(yea cool awesome stuff)
Now, I'm looking to make a variable corresponding to the item. so that:
yea = "yea"
cool = "cool"
awesome = "awesome"
stuff = "stuff"
My current method (which FAILS) is using eval
array.each {|item| eval(item + "=\"#{item}\"") }
I tested this with a puts instead of eval, and it comes out exactly
as it should. But when I try to use the variable, I get a
undefined local variable or method
error.
Bwah?
-------------------------------------------------------|
~ Ari
crap my sig won't fit