tags:

views:

95

answers:

1

In Ruby is there any method that lists all the global variables available at the point of inspection like $GLOBALS in php?

+1  A: 

Yes. There is Kernel#global_variables.

puts global_variables

Since it's a method from Kernel, you can call it without having to mention the class name.

Geo
@Geo: Thanks for the feedback. Is there any shortcut like $:, $. or something built-into ruby?
satynos
Ruby has some special variables, like in the way Perl does. See http://www.zenspider.com/Languages/Ruby/QuickRef.html , under the section `Predefined variables`.
Geo
@Geo: I did see the predefined variables in Ruby, but if I am not wrong, there is no predefined variable that acts as a shortcut to the global_variables method.
satynos
I don't think there is such a thing in Ruby.
Geo
I cannot find such a thing in the MRI 1.8.7 source
Wayne Conrad