Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Kernel#global_variables

global_variables → array

Returns an array of the names of global variables. This includes special regexp global variables such as $~ and $+, but does not include the numbered regexp global variables ($1, $2, etc.).

Example
global_variables.grep /std/   #=> [:$stdin, :$stdout, :$stderr]
See also #gets #gsub #gem #Hash also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0