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

ruby-changes:42751

From: akr <ko1@a...>
Date: Sat, 30 Apr 2016 10:57:41 +0900 (JST)
Subject: [ruby-changes:42751] akr:r54825 (trunk): {Fixnum, Bignum}#| is unified into Integer.

akr	2016-04-30 11:54:14 +0900 (Sat, 30 Apr 2016)

  New Revision: 54825

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

  Log:
    {Fixnum,Bignum}#| is unified into Integer.
    
    * numeric.c (int_or): {Fixnum,Bignum}#| is unified into
      Integer.
    
    * bignum.c (rb_big_or): Don't define Bignum#|.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c
    trunk/numeric.c
Index: bignum.c
===================================================================
--- bignum.c	(revision 54824)
+++ bignum.c	(revision 54825)
@@ -6556,13 +6556,6 @@ bigor_int(VALUE x, long xn, BDIGIT hibit https://github.com/ruby/ruby/blob/trunk/bignum.c#L6556
     return bignorm(z);
 }
 
-/*
- * call-seq:
- *     big | numeric   ->  integer
- *
- * Performs bitwise +or+ between _big_ and _numeric_.
- */
-
 VALUE
 rb_big_or(VALUE x, VALUE y)
 {
@@ -6978,7 +6971,6 @@ Init_Bignum(void) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6971
     rb_define_method(rb_cBignum, "fdiv", rb_big_fdiv, 1);
     rb_define_method(rb_cBignum, "**", rb_big_pow, 1);
     rb_define_method(rb_cBignum, "&", rb_big_and, 1);
-    rb_define_method(rb_cBignum, "|", rb_big_or, 1);
     rb_define_method(rb_cBignum, "~", rb_big_neg, 0);
 
     rb_define_method(rb_cBignum, "==", rb_big_eq, 1);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54824)
+++ ChangeLog	(revision 54825)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Apr 30 11:53:48 2016  Tanaka Akira  <akr@f...>
+
+	* numeric.c (int_or): {Fixnum,Bignum}#| is unified into
+	  Integer.
+
+	* bignum.c (rb_big_or): Don't define Bignum#|.
+
 Sat Apr 30 11:18:47 2016  Yuichiro Kaneko  <yui-knk@r...>
 
 	* vm_trace.c: Fix typos. [ci skip]
Index: numeric.c
===================================================================
--- numeric.c	(revision 54824)
+++ numeric.c	(revision 54825)
@@ -3913,9 +3913,9 @@ fix_and(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3913
 }
 
 /*
- * Document-method: Fixnum#|
+ * Document-method: Integer#|
  * call-seq:
- *   fix | integer  ->  integer_result
+ *   integer | integer  ->  integer_result
  *
  * Bitwise OR.
  */
@@ -3936,6 +3936,18 @@ fix_or(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3936
     return rb_funcall(x, '|', 1, y);
 }
 
+static VALUE
+int_or(VALUE x, VALUE y)
+{
+    if (FIXNUM_P(x)) {
+	return fix_or(x, y);
+    }
+    else if (RB_TYPE_P(x, T_BIGNUM)) {
+	return rb_big_or(x, y);
+    }
+    return Qnil;
+}
+
 /*
  * Document-method: Integer#^
  * call-seq:
@@ -4769,7 +4781,7 @@ Init_Numeric(void) https://github.com/ruby/ruby/blob/trunk/numeric.c#L4781
 
     rb_define_method(rb_cFixnum, "~", fix_rev, 0);
     rb_define_method(rb_cFixnum, "&", fix_and, 1);
-    rb_define_method(rb_cFixnum, "|", fix_or,  1);
+    rb_define_method(rb_cInteger, "|", int_or,  1);
     rb_define_method(rb_cInteger, "^", int_xor, 1);
     rb_define_method(rb_cInteger, "[]", int_aref, 1);
 

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

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