Nil.id #=> 4 ?!?!?!

$ ruby -e “puts nil.id; puts false.id; puts true.id”
4
0
2

This showed up as a bug in my code when finding records against nil
GOT RESULTS. I’ll need to override NilClass#id. :-/

I can certainly understand rationales for nil.respond_to?(:id) –
everything’s an object, etc., etc. But I also might suggest that the
id
of nil shouldn’t be 4?! Shouldn’t nil be able to be used as a
lightweight and/or primitive Null Object?

Nil is an object and therefore has a unique object id. Same with true
and false, all are singleton instances of their respective classes.

If you want to test whether an object is nil use #nil?. Only the
singleton instance of nil will respond as true, all other objects as
false.

Why are you checking for object id’s anyway? That is rarely useful if at
all. Besides, some c/c++ objects will give you a new ruby wrapper-object
everytime they are referenced (e.g. Method objects). That does not mean
that the underlying object is different.