“$-w = true”是做什么的?

What does "$-w = true" do?

我一直在阅读 Rack 的源代码,在 server.rb 我发现:

$-w = true

它正在为全局变量赋值。文档说:

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

但我仍然对全局变量的工作方式感到有点困惑,因为它不符合我理解的语言语法。

也试过这些:

$-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"
    ^

-w 是一个 Ruby 全局变量。

本文来自 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.