Raven Raven - 3 months ago 6
Ruby Question

What does "$-w = true" do?

I've been reading Rack's source code, and in server.rb I found:

$-w = true


It's assigning a value to a global variable. The documentation says:

Options may include:
# * :warn
# turn on warnings ($-w = true)


But still it is a bit confusing for me how that global variable works as it does not adhere to the language syntax I understand.

Also tried these:

$-w = "hello"
#=> "hello"

$-a = "hello"
#=> NameError: $-a is a read-only variable

$-b = "hello"
#=> "hello"

$-ww = "hello"
#=> SyntaxError: unexpected tIDENTIFIER, expecting end-of-input
$-ww = "hello"
^

Answer

-w is a Ruby global variable.

This is from the documentation:

$-0 The alias to $/.

$-a True if option -a is set. Read-only variable.

$-d The alias of $DEBUG. See $DEBUG above for further discusison.

$-F The alias to $;.

$-i In in-place-edit mode, this variable holds the extension, otherwise nil.

$-I The alias to $:.

$-l True if option -l is set. Read-only variable.

$-p True if option -p is set. Read-only variable.

$-v An alias of $VERBOSE. See $VERBOSE above for further discussion.

$-w An alias of $VERBOSE. See $VERBOSE above for further discussion.