Bug #12485 » rational-denom-to_int.patch
| rational.c | ||
|---|---|---|
|
a1 = string_to_r_strict(a1, raise);
|
||
|
if (!raise && NIL_P(a1)) return Qnil;
|
||
|
}
|
||
|
else if (!rb_respond_to(a1, idTo_r) && rb_respond_to(a1, rb_intern("to_int"))) {
|
||
|
a1 = rb_to_int(a1);
|
||
|
}
|
||
|
if (RB_FLOAT_TYPE_P(a2)) {
|
||
|
a2 = float_to_r(a2);
|
||
| ... | ... | |
|
a2 = string_to_r_strict(a2, raise);
|
||
|
if (!raise && NIL_P(a2)) return Qnil;
|
||
|
}
|
||
|
else if (a2 != Qundef && !rb_respond_to(a2, idTo_r) && rb_respond_to(a2, rb_intern("to_int"))) {
|
||
|
a2 = rb_to_int(a2);
|
||
|
}
|
||
|
if (RB_TYPE_P(a1, T_RATIONAL)) {
|
||
|
if (a2 == Qundef || (k_exact_one_p(a2)))
|
||
| test/ruby/test_rational.rb | ||
|---|---|---|
|
if (1.0/0).infinite?
|
||
|
assert_raise(FloatDomainError){Rational(1.0/0)}
|
||
|
end
|
||
|
o = Object.new
|
||
|
def o.to_int; 1; end
|
||
|
assert_equal(1, Rational(o, 1))
|
||
|
assert_equal(1, Rational(1, o))
|
||
|
assert_equal(1, Rational(o, o))
|
||
|
end
|
||
|
def test_attr
|
||
- « Previous
- 1
- 2
- Next »