From 6c0f7d19ba97b0a2116004d830a2565c2c0836d4 Mon Sep 17 00:00:00 2001 From: yugui Date: Sun, 21 Jun 2009 09:16:44 +0000 Subject: 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] git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_9_1@23793 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ complex.c | 2 ++ rational.c | 2 ++ test/ruby/test_complex.rb | 8 ++++++++ test/ruby/test_rational.rb | 6 ++++++ version.h | 2 +- 6 files changed, 26 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index b6fb9e356..97a1832b8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Wed Jun 17 08:14:01 2009 Tadayoshi Funaba + + * 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 * lib/webrick/httputils.rb (parse_form_data): escape boundary of diff --git a/complex.c b/complex.c index b3b55c685..62bc7a6f3 100644 --- a/complex.c +++ b/complex.c @@ -753,6 +753,8 @@ nucomp_coerce(VALUE self, VALUE other) { 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)); diff --git a/rational.c b/rational.c index 0dc445dfb..6d31c542a 100644 --- a/rational.c +++ b/rational.c @@ -902,6 +902,8 @@ nurat_coerce(VALUE self, VALUE other) 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", diff --git a/test/ruby/test_complex.rb b/test/ruby/test_complex.rb index 74d6d5dd8..39a02044f 100644 --- a/test/ruby/test_complex.rb +++ b/test/ruby/test_complex.rb @@ -505,6 +505,14 @@ class Complex_Test < Test::Unit::TestCase 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)) diff --git a/test/ruby/test_rational.rb b/test/ruby/test_rational.rb index cb7b58b41..8cacab9a0 100644 --- a/test/ruby/test_rational.rb +++ b/test/ruby/test_rational.rb @@ -704,6 +704,12 @@ class Rational_Test < Test::Unit::TestCase 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)) diff --git a/version.h b/version.h index 39806036e..05177b29a 100644 --- a/version.h +++ b/version.h @@ -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 -- cgit