The Perl and Raku Conference 2025: Greenville, South Carolina - June 27-29 Learn more

#!/usr/bin/ruby
global :a = (a => 1, b => 2)
assert_eq(a, Hash(a => 1, b => 2))
assert_eq(a{:a}, 1)
assert_eq(a{:b}, 2)
global *b = (1,2,3)
assert_eq(b, [1,2,3])
assert_eq(b[1], 2)
func foo() {
global xxx = 42
}
assert_eq(global xxx, nil) # not defined yet
foo() # define xxx
assert_eq(global xxx, 42) # should be defined
assert_eq(xxx, 42) # also available in the current scope (after accessing it once with `global`)
say "** Test passed!"