在Ruby中为什么$a和@a返回的是nil?
PHP中文网
PHP中文网 2017-04-25 09:03:55
0
2
1214

不应该是报错么?

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
大家讲道理

Uninitialized global variables and instance variables have default values ​​of nil.
You can take a look at the documentation:
http://www.rubyist.net/~slage...

Before initialization, a global variable has the special value nil.

http://www.rubyist.net/~slage...

instance variables have the nil value until they are initialized.

给我你的怀抱

Accessing an uninitialized variable returns nil, and nil can be regarded as an error.

Why? Because it is convenient, it is so troublesome to report errors every time and deal with them. Also, you are an awesome programmer, capable of using programming languages ​​well, and will not screw up the program because of nil (๑•̀ㅂ•́)و✧, so I won’t report an error.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template