> > nil.object_id
= > 4
原因是因为nil是一个固定的object,在如下在$rubyhome\lib\1.8\i386-mswin32中的ruby.h头文件里面有如下特殊对象的构造。
/* special contants - i.e. non-zero and non-fixnum constants */
#define Qfalse ((VALUE)0)
#define Qtrue ((VALUE)2)
#define Qnil ((VALUE)4)
#define Qundef ((VALUE)6) /* undefined value for placeholder */
在rails的activesupport里面,也有一个whiny_nil.rb的类有些相关的说明。