ruby-changes:12121
From: yugui <ko1@a...>
Date: Sun, 21 Jun 2009 18:17:03 +0900 (JST)
Subject: [ruby-changes:12121] Ruby:r23793 (ruby_1_9_1): merges r23718 from trunk into ruby_1_9_1.
yugui 2009-06-21 18:16:44 +0900 (Sun, 21 Jun 2009) New Revision: 23793 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=23793 Log: merges r23718 from trunk into ruby_1_9_1. -- * complex.c (nucomp_coerce): accepts Complex instances. * rational.c (nurat_coerce): accepts Rational instances. [ruby-core:23859] Modified files: branches/ruby_1_9_1/ChangeLog branches/ruby_1_9_1/complex.c branches/ruby_1_9_1/rational.c branches/ruby_1_9_1/test/ruby/test_complex.rb branches/ruby_1_9_1/test/ruby/test_rational.rb branches/ruby_1_9_1/version.h Index: ruby_1_9_1/complex.c =================================================================== --- ruby_1_9_1/complex.c (revision 23792) +++ ruby_1_9_1/complex.c (revision 23793) @@ -753,6 +753,8 @@ { if (k_numeric_p(other) && f_real_p(other)) return rb_assoc_new(f_complex_new_bang1(CLASS_OF(self), other), self); + if (TYPE(other) == T_COMPLEX) + return rb_assoc_new(other, self); rb_raise(rb_eTypeError, "%s can't be coerced into %s", rb_obj_classname(other), rb_obj_classname(self)); Index: ruby_1_9_1/ChangeLog =================================================================== --- ruby_1_9_1/ChangeLog (revision 23792) +++ ruby_1_9_1/ChangeLog (revision 23793) @@ -1,3 +1,10 @@ +Wed Jun 17 08:14:01 2009 Tadayoshi Funaba <tadf@d...> + + * complex.c (nucomp_coerce): accepts Complex instances. + + * rational.c (nurat_coerce): accepts Rational + instances. [ruby-core:23859] + Wed Jun 17 07:36:22 2009 NARUSE, Yui <naruse@r...> * lib/webrick/httputils.rb (parse_form_data): escape boundary of Index: ruby_1_9_1/version.h =================================================================== --- ruby_1_9_1/version.h (revision 23792) +++ ruby_1_9_1/version.h (revision 23793) @@ -1,6 +1,6 @@ #define RUBY_VERSION "1.9.1" #define RUBY_RELEASE_DATE "2009-05-22" -#define RUBY_PATCHLEVEL 183 +#define RUBY_PATCHLEVEL 184 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 9 #define RUBY_VERSION_TEENY 1 Index: ruby_1_9_1/test/ruby/test_complex.rb =================================================================== --- ruby_1_9_1/test/ruby/test_complex.rb (revision 23792) +++ ruby_1_9_1/test/ruby/test_complex.rb (revision 23793) @@ -505,6 +505,14 @@ end end + def test_coerce + assert_equal([Complex(2),Complex(1)], Complex(1).coerce(2)) + assert_equal([Complex(2.2),Complex(1)], Complex(1).coerce(2.2)) + assert_equal([Complex(Rational(2)),Complex(1)], + Complex(1).coerce(Rational(2))) + assert_equal([Complex(2),Complex(1)], Complex(1).coerce(Complex(2))) + end + def test_unify if @unify assert_instance_of(Fixnum, Complex(1,2) + Complex(-1,-2)) Index: ruby_1_9_1/test/ruby/test_rational.rb =================================================================== --- ruby_1_9_1/test/ruby/test_rational.rb (revision 23792) +++ ruby_1_9_1/test/ruby/test_rational.rb (revision 23793) @@ -704,6 +704,12 @@ assert_equal(false, Rational(1) == '') end + def test_coerce + assert_equal([Rational(2),Rational(1)], Rational(1).coerce(2)) + assert_equal([Rational(2.2),Rational(1)], Rational(1).coerce(2.2)) + assert_equal([Rational(2),Rational(1)], Rational(1).coerce(Rational(2))) + end + def test_unify if @unify assert_instance_of(Fixnum, Rational(1,2) + Rational(1,2)) Index: ruby_1_9_1/rational.c =================================================================== --- ruby_1_9_1/rational.c (revision 23792) +++ ruby_1_9_1/rational.c (revision 23793) @@ -902,6 +902,8 @@ return rb_assoc_new(f_rational_new_bang1(CLASS_OF(self), other), self); case T_FLOAT: return rb_assoc_new(other, f_to_f(self)); + case T_RATIONAL: + return rb_assoc_new(other, self); } rb_raise(rb_eTypeError, "%s can't be coerced into %s", -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/