ruby - "$-w = true"是做什么的?

标签 ruby rack

我一直在阅读 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/

相关文章:

ruby - 对Rack源码中的变量类型感到困惑

ruby-on-rails - Heroku 检测到 Rails 未设置为提供 static_assets

static - Heroku Cedar 纯 Rack 静态站点

ruby-on-rails - 如何使用 Rails 3/Rack 在没有 www 的情况下重定向?

ruby - 编写 Ruby 库 - 从模块外部隐藏方法

openssl生成指纹的Ruby代码

ruby-on-rails - 通过先写入 redis 来加速 web 服务,然后写入磁盘?

ruby - 我可以在后台写入文件吗?

ruby - class << self vs self.method with Ruby : what's better?

ruby-on-rails - 结合 Octopress 和 Rails 4.0 应用程序?