-3

How can I access variable by its name?

a = Hash.new
a["test"] = 9
some_method(:a) # => {"test" => 9}
sawa
  • 165,429
  • 45
  • 277
  • 381
Sato
  • 8,192
  • 17
  • 60
  • 115
  • 5
    Does this help? `a = 7; binding.local_variable_get(:a) #=> 7` or `eval("a") #=> 7`. – Cary Swoveland Jun 05 '15 at 01:55
  • 5
    There is a 99% probability this is an [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). What are you really trying to do? – Amadan Jun 05 '15 at 02:00

1 Answers1

3
a = Hash.new
a["test"] = 9
binding.local_variable_get(:a) # => {"test"=>9}
sawa
  • 165,429
  • 45
  • 277
  • 381