summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/numeric.c b/numeric.c
index 95a77d5e4c..948cba9a79 100644
--- a/numeric.c
+++ b/numeric.c
@@ -3889,9 +3889,9 @@ rb_num_coerce_bit(VALUE x, VALUE y, ID func)
}
/*
- * Document-method: Fixnum#&
+ * Document-method: Integer#&
* call-seq:
- * fix & integer -> integer_result
+ * integer & integer -> integer_result
*
* Bitwise AND.
*/
@@ -3912,6 +3912,18 @@ fix_and(VALUE x, VALUE y)
return rb_funcall(x, '&', 1, y);
}
+static VALUE
+int_and(VALUE x, VALUE y)
+{
+ if (FIXNUM_P(x)) {
+ return fix_and(x, y);
+ }
+ else if (RB_TYPE_P(x, T_BIGNUM)) {
+ return rb_big_and(x, y);
+ }
+ return Qnil;
+}
+
/*
* Document-method: Integer#|
* call-seq:
@@ -4780,7 +4792,7 @@ Init_Numeric(void)
rb_define_method(rb_cFixnum, "<=", fix_le, 1);
rb_define_method(rb_cFixnum, "~", fix_rev, 0);
- rb_define_method(rb_cFixnum, "&", fix_and, 1);
+ rb_define_method(rb_cInteger, "&", int_and, 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);