我一直在阅读 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.
关于ruby - "$-w = true"是做什么的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39003087/