Hi,

At Sat, 6 Jun 2009 06:06:34 +0900,
Run Paint Run Run wrote in [ruby-core:23729]:
> On 1.9.2 trunk `Time.now + 'glark'` succeeds, whereas on
> 1.9.1 and 1.8 it raised a TypeError. Presumably this is a
> regression.

To get number from rhs, now calls to_r method on it.
I think distinct implicit coercion and explicit conversion for
Rational are needed, like as to_int and to_i for Integer.


Index: object.c =================================================================== --- object.c (revision 23638) +++ object.c (working copy) @@ -2058,4 +2058,5 @@ rb_to_integer(VALUE val, const char *met if (FIXNUM_P(val)) return val; + if (TYPE(val) == T_BIGNUM) return val; v = convert_type(val, "Integer", method, Qtrue); if (!rb_obj_is_kind_of(v, rb_cInteger)) { @@ -2073,4 +2074,5 @@ rb_check_to_integer(VALUE val, const cha if (FIXNUM_P(val)) return val; + if (TYPE(val) == T_BIGNUM) return val; v = convert_type(val, "Integer", method, Qfalse); if (!rb_obj_is_kind_of(v, rb_cInteger)) { Index: rational.c =================================================================== --- rational.c (revision 23638) +++ rational.c (working copy) @@ -1652,4 +1652,6 @@ Init_Rational(void) rb_define_method(rb_cInteger, "to_r", integer_to_r, 0); rb_define_method(rb_cFloat, "to_r", float_to_r, 0); + rb_define_method(rb_cInteger, "to_rat", integer_to_r, 0); + rb_define_method(rb_cFloat, "to_rat", float_to_r, 0); make_patterns(); Index: time.c =================================================================== --- time.c (revision 23638) +++ time.c (working copy) @@ -199,9 +199,7 @@ num_exact(VALUE v) { VALUE tmp; - if (!NIL_P(tmp = rb_check_convert_type(v, T_RATIONAL, "Rational", "to_r"))) - v = tmp; - else if (!NIL_P(tmp = rb_check_convert_type(v, T_FIXNUM, "Integer", "to_int"))) + if (!NIL_P(tmp = rb_check_convert_type(v, T_RATIONAL, "Rational", "to_rat"))) v = tmp; - else if (!NIL_P(tmp = rb_check_convert_type(v, T_BIGNUM, "Integer", "to_int"))) + else if (!NIL_P(tmp = rb_check_to_integer(v, "to_int"))) v = tmp; else {
-- Nobu Nakada