开发者

How can I get a list of all variables in a binding?

开发者 https://www.devze.com 2022-12-18 04:14 出处:网络
Does a 开发者_开发知识库Binding know the variables it stores? Or do I always have to use this in conjunction with local_variables?You get the list of local variables in a binding by doing eval(\"local

Does a 开发者_开发知识库Binding know the variables it stores? Or do I always have to use this in conjunction with local_variables?


You get the list of local variables in a binding by doing eval("local_variables", the_binding).

I'm not sure whether that's what you meant by "Or do I always have to use this in conjunction with local_variables?", but there's no way to get the list without invoking local_variables somehow.


This is an older question, so the answer is correct for Ruby version <= 2

But since 2.1 new methods have appeared to get/set and list local variables:

local_variable_get  / local_variable_set / local_variable_defined?
0

精彩评论

暂无评论...
验证码 换一张
取 消