变量

    变量

    Ruby has three kinds of variables, one kind of constant and exactly two pseudo-variables.

    Ruby有3种类型的变量,一种是常量,另外两种是伪变量

    The variables and the constants have no type. While untyped variables have some drawbacks, they have many more advantages and fit well with ruby’s quick and easy philosophy.

    变量和常量都没有类型。尽管没有类型的变量有一些缺点,但是它们有远远更多的优点,并且与Ruby的快速和简单的哲学相适应。

    变量在大多数语言中必须声明,以指定它们的类型、可修改性(即:它们是否是常数)和作用域;因为类型不是问题,剩下的就是从变量名中可以看到的,正如你即将要看到的,在Ruby中使用变量不需要声明。

    The first character of an identifier categorizes it at a glance:

    标识符的第一个字符对它进行了分类:

    The only exceptions to the above are ruby’s pseudo-variables: self, which always refers to the currently executing object, and nil, which is the meaningless value assigned to uninitialized variables.

    上面的唯一例外是Ruby的伪变量:总是指向当前运行对象的和被赋给未初始化变量的无意义的值nil

    虽然两者都像是局部变量一样被命名,但是是由解释器维持的一个全局变量,而nil实际上是一个常量。

    As these are the only two exceptions, they don’t confuse things too much.

    因为这是仅有的2个例外,他们不会把事情搞得太混乱。

    You may not assign values to self or nil. main, as a value of self, refers to the top-level object:

    你不能给或nil赋值。,作为self的值,指的是顶级对象: