【问题标题】:What is @__instance__ in Ruby?Ruby 中的 @__instance__ 是什么?
【发布时间】:2020-09-13 09:46:53
【问题描述】:

Rails 在rails/activesupport/lib/active_support/inflector/inflections.rb 中使用它here

      @__instance__ = Concurrent::Map.new

Ruby variable name with double underscores中没有提到含义。

【问题讨论】:

  • 只是一个实例变量。下划线通常表示私人/内部使用。
  • 感谢 Stefan 的建设性回答。

标签: ruby variables


【解决方案1】:

下划线是标识符中的合法字符。没有任何意义。

(有一个例外:以下划线开头的局部变量如果未使用将不会生成警告。)

也就是说:@__instance__的意思和@foobar的意思完全一样:没有意思。

【讨论】:

    猜你喜欢
    • 2010-09-14
    • 1970-01-01
    • 1970-01-01
    • 2016-09-17
    • 2013-01-31
    • 2010-10-29
    • 2013-12-30
    • 2021-11-10
    • 2012-08-10
    相关资源
    最近更新 更多