From: "Eric I." Date: 2008-09-19T06:27:38+09:00 Subject: Re: variable name On Sep 18, 4:59 pm, Rick Tan wrote: > Is there a way in Ruby to use the content of a variable as the name of a > variable.  For example > > var1 = 'myVar' > > i want to assign a value to 'myVar' by referencing var1.  The name of > the variable can vary depending on the content of var1.  Other > application include using a variable to hold the name of a class method > which i need to call in my code. With eval you can do quite a bit: ==== v_name = "my_var" v_value = "5" eval "#{v_name} = #{v_value}" eval "puts my_var" # note: generates error puts my_var rescue puts "error" my_var = 0 # now initialize the variable in current binding eval "#{v_name} = #{v_value}" eval "puts my_var" # no error now puts my_var ==== Eric ==== Are you interested in on-site Ruby or Ruby on Rails training that uses well-designed, real-world, hands-on exercises? http://LearnRuby.com