Actions
Bug #12485
closedKernel.Rational raises TypeError though given denominator returns 1 by to_int
Description
Is it an intentional behavior?
class << (o = Object.new)
def to_int
1
end
end
Rational(1, o) #=> TypeError: not an integer
Files
Updated by mrkn (Kenta Murata) over 8 years ago
- File rational.c.diff rational.c.diff added
Attached patch can fix this issue.
Updated by nobu (Nobuyoshi Nakada) over 8 years ago
You can use RB_INTEGER_TYPE_P
in the trunk.
Updated by mrkn (Kenta Murata) over 8 years ago
Nobuyoshi Nakada wrote:
You can use
RB_INTEGER_TYPE_P
in the trunk.
I forgot it. Thanks.
Updated by jeremyevans0 (Jeremy Evans) over 5 years ago
I'm not sure if this is considered a bug or not. Rational will already try to convert numerator and denominator via to_r
. However, if we do want to convert via to_int
if to_r
is not defined, the attached patch should implement it.
Updated by mrkn (Kenta Murata) about 4 years ago
- Status changed from Open to Assigned
- Assignee set to mrkn (Kenta Murata)
I'm working on this at https://github.com/ruby/ruby/pull/3684
Updated by Anonymous about 4 years ago
- Status changed from Assigned to Closed
Applied in changeset git|d23d5c3130a0944e7e591370cbf8599009318a7c.
rational.c: try converting by to_int in Rational() (#3684)
[Bug #12485]
Actions
Like0
Like0Like0Like0Like0Like0Like0