def method
a = 3
b = 4
some_method_that_gives # [a, b]
end
def method
a = 3
b = 4
some_method_that_gives # [a, b]
end
该函数输出代表变量的符号数组。在你的情况下为:[:a, :b]
local_variables
列出了本地变量,但是它会在定义之前就列出它们。请看这个例子:
p local_variables
a = 1
p local_variables
这会输出
。[:a]
[:a]
这可能不是您所期望的。与defined?
相比较。
p defined? a
a = 1
p defined? a
输出更多期望的内容
nil
"local-variable"
variables = self.local_variables.each_with_object({}) { |key, hash| hash[key] = eval(key.to_s) }