From: Robert Dober Date: 2007-04-18T18:57:03+09:00 Subject: Re: nil in evaluations On 4/18/07, progcat@comcast.net wrote: > Close but not really what I was looking for. > > example: > if g(x) > f(x) > then > put "rejoice because f(x) is greater than f(x)" > else > put "g(x) <= f(x) OR g(x) and/or f(x) returned a nil so I > wanted to execute this" > end. > > In other words I want the function to work as it normally would for > valid values, and if one or both are nil I want to make the test > evaluate to false. You ask nil to be greater than any other value and you ask nil to be smaller than any other value at the same time. I think you should rethink your modeling a bit. Of course you can do it by defining Nil#> and redefine X#> for all X that can be returned by g, but as Robert has pointed out correctly: Think twice before doing this. The quick hack if you really need it should look similar to class Nil def >; false end ## I guess nil is a better choice than false end class Integer alias_method :old_gr, :> def > other return false if other.nil? old_gr other end end I you use it in production you will be bitten, be aware of it. HTH Robert > > Sorry I was not clear. > > Thanks, > Tom > -- You see things; and you say Why? But I dream things that never were; and I say Why not? -- George Bernard Shaw