如何通过名称访问变量

时间:2015-06-05 01:42:13

标签: ruby local-variables

如何通过名称访问变量?

a = Hash.new
a["test"] = 9
some_method(:a) # => {"test" => 9}

1 个答案:

答案 0 :(得分:3)

a = Hash.new
a["test"] = 9
binding.local_variable_get(:a) # => {"test"=>9}