3

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

2
  • Should this question be tagged reflection, or tagged metaprogramming? Commented Mar 1, 2010 at 22:33
  • 1
    Does $GLOBALS get included in $GLOBALS in PHP? Commented Apr 4, 2011 at 7:27

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

5 Comments

@Geo: Thanks for the feedback. Is there any shortcut like $:, $. or something built-into ruby?
Ruby has some special variables, like in the way Perl does. See zenspider.com/Languages/Ruby/QuickRef.html , under the section Predefined variables.
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.
I don't think there is such a thing in Ruby.
I cannot find such a thing in the MRI 1.8.7 source

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.