Does a Binding
know the variables it stores? Or do I always have to use this in conjunction with local_variables
?
views:
22answers:
1
+1
A:
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.
sepp2k
2010-01-21 11:57:42
I was thinking the binding had a method which would list all the values it contained ( so that I wouldn't have to pass along the array returned by `local_variables` )
Geo
2010-01-21 12:04:52
Well, you don't have to pass it along because you can get it at any time using eval. There is no method though, unless you define one `class Binding; def variables() self.eval("local_variables") end end`
sepp2k
2010-01-21 12:19:56