--YuJye9aIuN0w6xGV Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable John Platte (john.platte / nikaconsulting.com) wrote: > Subject line says it all: nil.id #=> 4 !!! > > $ ruby -v > ruby 1.8.1 (2003-12-25) [powerpc-darwin] > $ ruby -e "puts nil.id; puts false.id; puts true.id" > 4 > 0 > 2 See ruby.h, look for "#define Qnil" around line 171. > This showed up as a bug in my code when finding records against nil > *GOT RESULTS*. I'll need to override NilClass#id. :-/ Why do you need nil's #object_id to be any particular special value? > 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? What should it be? Note: $ ruby -e '(0..10).each do |x| puts "\#{x}: \#{x.object_id}" end' 0: 1 1: 3 2: 5 3: 7 4: 9 5: 11 6: 13 7: 15 8: 17 9: 19 10: 21 In other words, an odd #object_id is a Fixnum, while an even #object_id is a reference to an Object. -- Eric Hodel - drbrain / segment7.net - http://segment7.net All messages signed with fingerprint: FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04 --YuJye9aIuN0w6xGV Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQFAtSQ4MypVHHlsnwQRAo2uAJ9pQAJL4kzxlSqhaKsvLHk/Zt4dYwCbBcNZ zHK9K2GJN5EoXsbUcSkP3Lc KK -----END PGP SIGNATURE----- --YuJye9aIuN0w6xGV--