In Ruby is there any method that lists all the global variables available at the point of inspection like $GLOBALS
in php?
views:
95answers:
1
+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
2010-03-01 16:38:54
@Geo: Thanks for the feedback. Is there any shortcut like $:, $. or something built-into ruby?
satynos
2010-03-01 16:47:21
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
2010-03-01 16:49:12
@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
2010-03-01 16:55:23
I don't think there is such a thing in Ruby.
Geo
2010-03-01 17:48:22
I cannot find such a thing in the MRI 1.8.7 source
Wayne Conrad
2010-03-01 20:59:52