Ruby中的Magic $ -prefixed变量;在哪里有完整的参考?

时间:2022-12-26 16:09:07

I've seen magic variables like this used in Ruby. $_ $' $0

我在Ruby中看过像这样的魔术变量。 $ _ $'$ 0

Is there a complete reference for what all of them mean and how they are set?

是否有完整的参考资料来说明它们的含义以及它们是如何设定的?

3 个解决方案

#1


34  

Their name is global variables. There are several different references.

他们的名字是全局变量。有几个不同的参考。

You can get a full list by calling the method Kernel#global_variables

您可以通过调用Kernel#global_variables方法获取完整列表

puts global_variables

Ruby also includes a file called "English.rb" in the standard library which provides an in-depth explanation of several global variables.

Ruby还在标准库中包含一个名为“English.rb”的文件,该文件提供了对几个全局变量的深入解释。

Also, there's (an archived version of) "Cryptic Ruby Global Variables and Their Meanings".

此外,还有(Cryived Ruby Global Variables及其含义)的存档版本。

Finally, the Ruby Programming wikibook has a "Predefined Variables" reference.

最后,Ruby Programming wikibook有一个“预定义变量”参考。

#2


4  

They are called "global variables" (complete list at the bottom of the page): http://www.rubyist.net/~slagell/ruby/globalvars.html

它们被称为“全局变量”(页面底部的完整列表):http://www.rubyist.net/~slagell/ruby/globalvars.html

#3


2  

The Ruby documentation used to be very class orientated. In recent versions of Ruby however there are rdoc files about literals, precedence, syntax, globals and much more.

Ruby文档过去非常以类为导向。在最近的Ruby版本中,有关于文字,优先级,语法,全局等的rdoc文件。

#1


34  

Their name is global variables. There are several different references.

他们的名字是全局变量。有几个不同的参考。

You can get a full list by calling the method Kernel#global_variables

您可以通过调用Kernel#global_variables方法获取完整列表

puts global_variables

Ruby also includes a file called "English.rb" in the standard library which provides an in-depth explanation of several global variables.

Ruby还在标准库中包含一个名为“English.rb”的文件,该文件提供了对几个全局变量的深入解释。

Also, there's (an archived version of) "Cryptic Ruby Global Variables and Their Meanings".

此外,还有(Cryived Ruby Global Variables及其含义)的存档版本。

Finally, the Ruby Programming wikibook has a "Predefined Variables" reference.

最后,Ruby Programming wikibook有一个“预定义变量”参考。

#2


4  

They are called "global variables" (complete list at the bottom of the page): http://www.rubyist.net/~slagell/ruby/globalvars.html

它们被称为“全局变量”(页面底部的完整列表):http://www.rubyist.net/~slagell/ruby/globalvars.html

#3


2  

The Ruby documentation used to be very class orientated. In recent versions of Ruby however there are rdoc files about literals, precedence, syntax, globals and much more.

Ruby文档过去非常以类为导向。在最近的Ruby版本中,有关于文字,优先级,语法,全局等的rdoc文件。