[前][次][番号順一覧][スレッド一覧]

ruby-changes:20945

From: mrkn <ko1@a...>
Date: Wed, 17 Aug 2011 10:24:32 +0900 (JST)
Subject: [ruby-changes:20945] mrkn:r32994 (trunk): * rational.c (nurat_coerce): Rational#coerce should converts itself

mrkn	2011-08-17 10:24:22 +0900 (Wed, 17 Aug 2011)

  New Revision: 32994

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32994

  Log:
    * rational.c (nurat_coerce): Rational#coerce should converts itself
      into Complex if the argument is a Complex with non-zero imaginary
      part.  [Bug #5020] [ruby-dev:44088]
    * test/ruby/test_rational.rb (test_coerce): test for the above change.

  Modified files:
    trunk/ChangeLog
    trunk/rational.c
    trunk/test/ruby/test_rational.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 32993)
+++ ChangeLog	(revision 32994)
@@ -1,3 +1,11 @@
+Wed Aug 17 10:16:00 2011  Kenta Murata  <mrkn@m...>
+
+	* rational.c (nurat_coerce): Rational#coerce should converts itself
+	  into Complex if the argument is a Complex with non-zero imaginary
+	  part.  [Bug #5020] [ruby-dev:44088]
+
+	* test/ruby/test_rational.rb (test_coerce): test for the above change.
+
 Wed Aug 17 06:33:19 2011  Martin Bosslet  <Martin.Bosslet@g...>
 
 	* ext/openssl/ossl_x509cert.c: Add class documentation for
@@ -38,6 +46,7 @@
 Mon Aug 15 09:58:55 2011  Martin Bosslet  <Martin.Bosslet@g...>
 
 	* ext/openssl/ossl_ssl.c: Support disabling OpenSSL compression.
+
 	* test/openssl/test_ssl.rb: Add a test for it.
 	  Thanks to Eric Wong for the patch.
 	  [Ruby 1.9 - Feature #5183] [ruby-core:38911]
@@ -70,12 +79,14 @@
 
 	* ext/psych/lib/psych/core_ext.rb: Make Kernel#y private.
 	  [ruby-core:38913]
+
 	* test/psych/test_yaml.rb: corresponding test.
 
 Sat Aug 13 09:05:16 2011  Tadayoshi Funaba  <tadf@d...>
 
 	* ext/date/date_core.c (date_strftime_alloc): followed the change
 	  of r32885.
+
 	* doc/NEWS-1.9.3: followed the above change.
 
 Sat Aug 13 08:55:38 2011  Aaron Patterson <aaron@t...>
@@ -228,7 +239,9 @@
 Tue Aug  9 09:18:04 2011  Eric Hodel  <drbrain@s...>
 
 	* ext/zlib/zlib.c (gzfile_wrap):  Document encoding options.
+
 	* ext/zlib/zlib.c (rb_gzwriter_s_open): ditto
+
 	* ext/zlib/zlib.c (rb_gzreader_s_open): ditto
 
 Sun Aug  7 23:31:32 2011  KOSAKI Motohiro  <kosaki.motohiro@g...>
@@ -243,7 +256,9 @@
 
 	* ext/openssl/ossl_asn1.c (decode_eoc): remove unused variables.
 	  Patch by Eric Wong. [Feature #5157] [ruby-core:38798]
+
 	* ext/openssl/ossl_asn1.c (ossl_asn1_decode): ditto.
+
 	* ext/openssl/ossl_pkey.c (ossl_pkey_new_from_data): ditto.
 
 Sun Aug  7 22:37:08 2011  KOSAKI Motohiro  <kosaki.motohiro@g...>
Index: test/ruby/test_rational.rb
===================================================================
--- test/ruby/test_rational.rb	(revision 32993)
+++ test/ruby/test_rational.rb	(revision 32994)
@@ -721,6 +721,10 @@
     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)))
+
+    assert_nothing_raised(TypeError, '[Bug #5020] [ruby-devl:44088]') do
+      Rational(1,2).coerce(Complex(1,1))
+    end
   end
 
   class ObjectX
Index: rational.c
===================================================================
--- rational.c	(revision 32993)
+++ rational.c	(revision 32994)
@@ -1108,6 +1108,8 @@
 	if (k_exact_zero_p(RCOMPLEX(other)->imag))
 	    return rb_assoc_new(f_rational_new_bang1
 				(CLASS_OF(self), RCOMPLEX(other)->real), self);
+	else
+	    return rb_assoc_new(other, rb_Complex(self, INT2FIX(0)));
     }
 
     rb_raise(rb_eTypeError, "%s can't be coerced into %s",

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]