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

Forum statistics

Threads
474,285
Messages
2,571,416
Members
48,107
Latest member
AmeliaAmad

Latest Threads

Top