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

ruby-changes:42772

From: akr <ko1@a...>
Date: Sat, 30 Apr 2016 19:21:24 +0900 (JST)
Subject: [ruby-changes:42772] akr:r54846 (trunk): Define Integer#== instead of Bignum#==.

akr	2016-04-30 20:18:00 +0900 (Sat, 30 Apr 2016)

  New Revision: 54846

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54846

  Log:
    Define Integer#== instead of Bignum#==.
    
    * numeric.c (int_equal): Define Integer#==.
    
    * bignum.c (rb_big_eq): Don't define Bignum#==.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c
    trunk/numeric.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54845)
+++ ChangeLog	(revision 54846)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Apr 30 20:17:08 2016  Tanaka Akira  <akr@f...>
+
+	* numeric.c (int_equal): Define Integer#==.
+
+	* bignum.c (rb_big_eq): Don't define Bignum#==.
+
 Sat Apr 30 19:41:15 2016  Tanaka Akira  <akr@f...>
 
 	* numeric.c (int_gt): Define Integer#>.
Index: numeric.c
===================================================================
--- numeric.c	(revision 54845)
+++ numeric.c	(revision 54846)
@@ -3747,11 +3747,14 @@ rb_int_pow(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3747
 }
 
 /*
+ * Document-method: Integer#==
  * Document-method: Fixnum#==
  * call-seq:
- *   fix == other  ->  true or false
+ *   int == other  ->  true or false
  *
- * Return +true+ if +fix+ equals +other+ numerically.
+ * Return +true+ if +int+ equals +other+ numerically.
+ * Contrast this with <code>Integer#eql?</code>, which
+ * requires <i>other</i> to be a <code>Integer</code>.
  *
  *   1 == 2      #=> false
  *   1 == 1.0    #=> true
@@ -3773,6 +3776,18 @@ fix_equal(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3776
     }
 }
 
+static VALUE
+int_equal(VALUE x, VALUE y)
+{
+    if (FIXNUM_P(x)) {
+	return fix_equal(x, y);
+    }
+    else if (RB_TYPE_P(x, T_BIGNUM)) {
+	return rb_big_eq(x, y);
+    }
+    return Qnil;
+}
+
 /*
  *  Document-method: Integer#<=>
  *  call-seq:
@@ -4937,6 +4952,7 @@ Init_Numeric(void) https://github.com/ruby/ruby/blob/trunk/numeric.c#L4952
     rb_define_method(rb_cInteger, "abs", int_abs, 0);
     rb_define_method(rb_cInteger, "magnitude", int_abs, 0);
 
+    rb_define_method(rb_cInteger, "==", int_equal, 1);
     rb_define_method(rb_cInteger, ">", int_gt, 1);
     rb_define_method(rb_cInteger, ">=", int_ge, 1);
     rb_define_method(rb_cInteger, "<", int_lt, 1);
Index: bignum.c
===================================================================
--- bignum.c	(revision 54845)
+++ bignum.c	(revision 54846)
@@ -6848,7 +6848,6 @@ Init_Bignum(void) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6848
     rb_define_method(rb_cBignum, "/", rb_big_div, 1);
     rb_define_method(rb_cBignum, "%", rb_big_modulo, 1);
 
-    rb_define_method(rb_cBignum, "==", rb_big_eq, 1);
     rb_define_method(rb_cBignum, "===", rb_big_eq, 1);
 
 #ifdef USE_GMP

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

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