Joel VanderWerf
3/6/2008 6:57:00 AM
svy wrote:
> Is there any way to determine what local variables are currently
> defined? (possibly using binding? thread?)
> Is there any way similar to how an array of current instance variables
> can be found?
> Thanks
Use the #local_variables and the #instance_variables methods.
class C
def foo
x = 1
y = 2
p local_variables
z = 3 # note z is included
@x = 10
@y = 20
p instance_variables
@z = 3 # note @z is _not_ included
end
end
C.new.foo
__END__
Output:
["x", "y", "z"]
["@y", "@x"]
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407