Determining local variables

S

svy

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
 
J

Joel VanderWerf

svy said:
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"]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top