Determining local variables

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

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”]