From: "Berger, Daniel" Date: 2007-11-13T07:34:48+09:00 Subject: Re: Time#== bug? > -----Original Message----- > From: murphy [mailto:murphy@rubychan.de] > Sent: Monday, November 12, 2007 12:55 PM > To: ruby-core@ruby-lang.org > Subject: Re: Time#== bug? > > Jim Weirich wrote: > > On Nov 12, 2007, at 12:09 PM, Berger, Daniel wrote: > >> Looks like Time#== always returns nil when compared against an > >> invalid type. All the other Comparable operators return an > ArgumentError: > > I don't think it should ever be an error to ask if an > object is equal > > to any other object. Nil (or false) would be the correct > response in > > the example you gave. > not all Comparable operators: the funny thing is that > Time.now <=> 0 returns nil, too...I would expect it to throw > an error. but "" <=> :foo and 4.3 <=> // also return nil, so > I guess it's by design. Yes, it does indeed appear to be the way <=> is designed in compar.c: static VALUE cmp_eq(a) VALUE *a; { VALUE c = rb_funcall(a[0], cmp, 1, a[1]); if (NIL_P(c)) return Qnil; /* <--- HERE */ if (rb_cmpint(c, a[0], a[1]) == 0) return Qtrue; return Qfalse; } I'm not really sure why compar.c does this, though, instead of returning false. Regards, Dan This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments.