Project

General

Profile

Actions

Bug #1636

closed

Rational#coerce(Rational) Raises TypeError

Added by runpaint (Run Paint Run Run) over 15 years ago. Updated over 13 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.2dev (2009-06-14 trunk 23689) [i686-linux]
Backport:
[ruby-core:23859]

Description

=begin
On 1.9.2 trunk:

 >> Rational(2).coerce(Rational(2))
 TypeError: Rational can't be coerced into Rational
from (irb):1:in `coerce'
from (irb):1
from /usr/local/bin/irb:12:in `<main>'

However:

 >> 2.coerce(2)
 => [2, 2]

 >> 2.2.coerce(2.2)
 => [2.2, 2.2]

Indeed, the documentation for Numeric#coerce states "If aNumeric is the same type as num, returns an array containing aNumeric and num."

It also works on 1.8.7:

 >> Rational(1).coerce(Rational(1)
 => [Rational(1, 1), Rational(1, 1)]

I suspect this should be special cased, for consistency if nothing else.
=end

Actions #1

Updated by tadf (tadayoshi funaba) over 15 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
Applied in changeset r23718.
=end

Actions

Also available in: Atom PDF

Like0
Like0