globals/global_variables_list.rb

tests/_examples/globals/global_variables_list.rb in the metorex repository.

names = global_variables

puts names.include?(:$stdout)
puts names.include?(:$stderr)
puts names.include?(:$stdin)
puts names.include?(:$never_assigned)

before = global_variables.size
$freshly_assigned = 1
puts global_variables.size - before
puts global_variables.include?(:$freshly_assigned)

puts global_variables.grep(/std/).sort.inspect

words = ["apple", "banana", "avocado"]
puts words.grep(/^a/).inspect
puts words.grep_v(/^a/).inspect
puts words.grep(/^a/) { |word| word.upcase }.inspect

mixed = [1, "two", :three, 4]
puts mixed.grep(Integer).inspect

puts Kernel.private_instance_methods.include?(:global_variables)

Output:

true
true
true
false
1
true
[:$stderr, :$stdin, :$stdout]
["apple", "avocado"]
["banana"]
["APPLE", "AVOCADO"]
[1, 4]
true