In Ruby is there any method that lists all the global variables available at the point of inspection like $GLOBALS in php?
1 Answer
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.
5 Comments
Dharam Gollapudi
@Geo: Thanks for the feedback. Is there any shortcut like $:, $. or something built-into ruby?
Geo
Ruby has some special variables, like in the way Perl does. See zenspider.com/Languages/Ruby/QuickRef.html , under the section
Predefined variables.Dharam Gollapudi
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.
Geo
I don't think there is such a thing in Ruby.
Wayne Conrad
I cannot find such a thing in the MRI 1.8.7 source
reflection, or taggedmetaprogramming?$GLOBALSget included in$GLOBALSin PHP?