On 10/15/07, Chad Perrin <perrin / apotheon.com> wrote: > On Mon, Oct 15, 2007 at 04:40:35AM +0900, Gerardo Santana G?mez Garrido wrote: > > > > What does nil.to_i return? Zero. And I wonder why. How can nil be > > interpreted as a number. It's beyond me. > > There's been a few attempts to answer the question already. I'm curious, > though: > > What would you expect it to return, and why would you think that should > be the expected behavior? > > Nothing immediately occurs to me as a better result of evaluating > nil.to_i than 0, within the context of the Ruby language, but if you have > an alternative view I'm open to learning from it. nil.to_i # > NoMethodError: undefined method `to_i' for nil:NilClass Integer(nil) # > TypeError: can't convert nil into Integer This is on my wish list for Christmas among other things.