From: Robert Dober Date: 2007-03-15T07:26:49+09:00 Subject: Re: Nil Comparable On 3/14/07, Ronnie wrote: > ara.t.howard@noaa.gov wrote: > > On Wed, 14 Mar 2007, Trans wrote: > > > >> Does anyone see anything problematic about this? > >> > >> class NilClass > >> > >> include Comparable > >> > >> def <=>(x) > >> x.nil? ? 0 : -1 > >> end > >> > >> def succ; nil; end > >> > >> end > >> > >> It seems benign enough, and can be used to represent "always before". > >> For instance, in Rake there is a class called EarlyTime: "EarlyTime is > >> a fake timestamp that occurs before any other time value." And that's > >> all that it does. If NilClass were comparable per the above then > >> EarlyTime would not be needed. > > > > it could mask errors like > > > > [42, nil].sort > > > > depending on the order of comparison it may or may not work since we > > might get > > > > 42.send '<=>', nil > > > > or > > > > nil.send '<=>', 42 > > > > so it's a bit different in that it's weakly typed where as the > > EarlyTime class > > is strongly typed - it'll only compare with other times > > > > still - it __is__ handy. if you search the archives i've suggeted that > > -Infinity and Infinity have these kinds of properties wrst numerics a few > > times. > > > > cheers. > > > > -a > The Facets library includes all of the above-mentioned features of > usefulness. > http://facets.rubyforge.org/ > There are a lot of other extensions to the Ruby core in it, and they can > mostly be included in small chunks, so they are easy to use. > I hope this helps! Well I guess Tom knows about Facets Ronnie :) http://rubyforge.org/projects/facets/ as you might know this link :). > > Thus spake the monkey > > It must be quite rewarding though to get pointed to your own project I would love that ;) Cheers Robert -- You see things; and you say Why? But I dream things that never were; and I say Why not? -- George Bernard Shaw