x = 1 varname = "x" eval(varname) # => 1 eval("varname = '$g'") # Set varname to "$g" eval("#{varname} = x") # Set $g to 1 eval(varname) # => 1