From: Robert Dober Date: 2006-08-18T05:09:31+09:00 Subject: Re: How to - Change operator behaviour ------=_Part_126971_25210577.1155845369786 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 8/17/06, Henry Savr wrote: > > Dear Ruby gurus: > > I want to write anywhere in my code t1 > t2 and get: > - true if at least one parameter is nil and the other parameter is > Time > - standard comparision result in other case > > > How to do that? > > Thank you > Henry > > -- > Posted via http://www.ruby-forum.com/. > > Well if you really want to do that here you go #!/usr/local/bin/ruby -w class NilClass def > other return true if Time =3D=3D=3D other raise NoMethodError, "undefined method `>' for nil:NilClass" end end class Time alias_method :old_greater, :> def > other return true if other.nil? old_greater other end end def show bool, text1, text2 puts bool ? text1 : text2 end t1 =3D Time.new t2 =3D Time.new show t1 > t2, "error", "t1 is not > t2" show t2 > t1, "t2 > t1", "error" show t1 > nil, "t1 > nil", "error" show nil > t2, "nil > t2", "error" nil > 2 Strange though?? Cheers Robert --=20 Deux choses sont infinies : l'univers et la b=EAtise humaine ; en ce qui concerne l'univers, je n'en ai pas acquis la certitude absolue. - Albert Einstein ------=_Part_126971_25210577.1155845369786--