Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Ruby中有没有一种方法可以初始化从*下划线*开始的变量,例如变量名_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails Ruby中有没有一种方法可以初始化从*下划线*开始的变量,例如变量名

Ruby on rails Ruby中有没有一种方法可以初始化从*下划线*开始的变量,例如变量名,ruby-on-rails,ruby,Ruby On Rails,Ruby,我相信Ruby默认支持这一点。 我需要创建一堆类变量,但不想覆盖已经定义的变量,也不知道其中哪些已经定义。 我希望类似于class_属性,但它应该创建以下划线开头的变量。是。变量可以以下划线开头。例如: _hello = "_hello" hello = "hello" puts _hello #=> "_hello" puts hello #=> "hello" ActiveSupport具有attr\u internal。这里有一个问题: 对于class属性,只需使用cla

我相信Ruby默认支持这一点。 我需要创建一堆类变量,但不想覆盖已经定义的变量,也不知道其中哪些已经定义。
我希望类似于class_属性,但它应该创建以下划线开头的变量。

是。变量可以以下划线开头。例如:

_hello = "_hello"
hello = "hello"

puts _hello
#=> "_hello"

puts hello
#=> "hello"

ActiveSupport具有
attr\u internal
。这里有一个问题:


对于class属性,只需使用
class,我就可以编写class\u属性:\u my\u var,但我几乎可以肯定应该有class\u xxx\u属性:my\u varsame@user2819006我不太明白。。没有
class\u xxx\u属性:my\u var
,如果有。为什么它会给你
\u my\u var
?我记得我一直在读关于允许初始化此类变量的方法,不幸的是,我在文档中找不到这一点。