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?
精彩评论