From: John Platte Date: 2004-05-27T07:42:43+09:00 Subject: Re: nil.id #=> 4 ?!?!?! On 2004 May 26, at 17:08, Hal Fulton wrote: >> 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? > > Why are you testing the value of nil.id? You know nil is nil > already. The ids are the way they are because the first two bits convey > information. > > I suggest you just live with this. And I suggest that if you are > checking the id of nil, your code is likely flawed in concept. SQL. I'm inheriting from OpenStruct to create an active record object (inspired by Mr. Rails, but found it a better fit to roll my own simpler version). It works deliciously except for this -- I can plop SQL results directly into this little Record object, overload behavior really easily. And the primary key column is called "id", so that's where the primary key info lives. You're probably right -- I'm copping out of using a real "NullRecord". I'll keep a nose out for more smells and look for the sources of nil that should be emitting a "NullRecord" instead. Thanks. -- Ryan "John" Platte Custom services, NIKA Consulting http://nikaconsulting.com/