From: Jim Cropcho Date: 2008-02-02T02:34:41+09:00 Subject: Re: Incorrect Time#<=> specification ------=_Part_27917_31239652.1201887288651 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I agree that <=3D> should only compare two temporal objects of the same cla= ss, which is how the method is currently constructed. My patch for a Temporal mixin: http://www.ruby-forum.com/topic/139881#622989 which is currently being considered for inclusion into the Ruby core, allow= s developers to write code which reinforces this constraint on comparisons by using the more domain-specific terms "before" and "after" to compare Times, Dates, etc. For example, it's conceivable a developer might attempt some_time <=3D> 10039483 but they would certainly be much less likely to try some_time.before? 10039483 because the vocabulary more precisely describes what the program is doing. That being said, +1 for Vladimir's patch. On Feb 1, 2008 9:09 AM, Vladimir Sizikov wrote: > Hi, > > Currently (in both, MRI 1.8.6 and 1.9) the docs for Time#<=3D> state > that the Time object can > be compared with Numeric argument: > > "Difference=97Returns a new time that represents the difference between t= wo > times, > or subtracts the given number of seconds in numeric from time." > > But this is not what the code does. The code compares only Time instances= , > and returns nil for everything else. I was able to dig up the history > and it seems, > that the change was intentional in rev. 3823, with comment: > " time.c (time_cmp): does not compare with numbers for > interchangeability. (ruby-bugs-ja PR#458)" > > So it seems that the description should be updated to match the behavior. > > Here's the simple patch against 1.8 branch, but similar thing applies > to trunk too. > > Thanks, > --Vladimir > > P.S. Can somebody tell me where can I find that ruby-bugs-ja PR#458 > online? > ------=_Part_27917_31239652.1201887288651 Content-Type: text/html; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I agree that <=3D> should only compare two temporal objects of the sa= me class, which is how the method is currently constructed. My patch for a = Temporal mixin:

http://www.ruby-forum.com/topic/139881#622989

which is currently being considered for inclusion into the Ruby core, a= llows developers to write code which reinforces this constraint on comparis= ons by using the more domain-specific terms "before" and "af= ter" to compare Times, Dates, etc. For example, it's conceivable a= developer might attempt

some_time <=3D> 10039483

but they would certainly be much = less likely to try

some_time.before? 10039483

because the voc= abulary more precisely describes what the program is doing.

That bei= ng said,

+1 for Vladimir's patch.

On Feb 1= , 2008 9:09 AM, Vladimir Sizikov <= vsizikov@gmail.com> wrote:
Hi,

Currently (in both, MRI 1.8.6 and 1.9) the docs for Time#<=3D= > state
that the Time object can
be compared with Numeric argument= :

"Difference=97Returns a new time that represents the differen= ce between two times,
or subtracts the given number of seconds in numeric from time."
But this is not what the code does. The code compares only Time instances,=
and returns nil for everything else. I was able to dig up the history and it seems,
that the change was intentional in rev. 3823, with comment= :
" time.c (time_cmp): does not compare with numbers for
 = interchangeability. (ruby-bugs-ja PR#458)"

So it seems that the= description should be updated to match the behavior.

Here's the simple patch against 1.8 branch, but similar thing appli= es
to trunk too.

Thanks,
 --Vlad= imir

P.S. Can somebody tell me where can I find that ruby-bug= s-ja PR#458 online?

------=_Part_27917_31239652.1201887288651--