summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-30 05:05:54 (GMT)
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-30 05:05:54 (GMT)
commit1b1a1ed6c8faeb41d4299dbbdd477713ab19e8b2 (patch)
tree0683445959d32b2b20f88be43c5dfc98eee36c31 /numeric.c
parentbda463c134c28da140426f9795c694a5bd17de2e (diff)
{Fixnum,Bignum}#divmod is unified into Integer.
* numeric.c (int_divmod): {Fixnum,Bignum}#divmod is unified into Integer. * bignum.c (rb_big_divmod): Don't define Bignum#divmod. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54834 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/numeric.c b/numeric.c
index 95444b3..f291e3a 100644
--- a/numeric.c
+++ b/numeric.c
@@ -3536,11 +3536,11 @@ rb_int_modulo(VALUE x, VALUE y)
}
/*
- * Document-method: Fixnum#divmod
+ * Document-method: Integer#divmod
* call-seq:
- * fix.divmod(numeric) -> array
+ * integer.divmod(numeric) -> array
*
- * See Numeric#divmod.
+ * See <code>Numeric#divmod</code>.
*/
static VALUE
fix_divmod(VALUE x, VALUE y)
@@ -3571,6 +3571,18 @@ fix_divmod(VALUE x, VALUE y)
}
}
+static VALUE
+int_divmod(VALUE x, VALUE y)
+{
+ if (FIXNUM_P(x)) {
+ return fix_divmod(x, y);
+ }
+ else if (RB_TYPE_P(x, T_BIGNUM)) {
+ return rb_big_divmod(x, y);
+ }
+ return Qnil;
+}
+
/*
* Document-method: Integer#**
* call-seq:
@@ -4830,7 +4842,7 @@ Init_Numeric(void)
rb_define_method(rb_cFixnum, "div", fix_idiv, 1);
rb_define_method(rb_cFixnum, "%", fix_mod, 1);
rb_define_method(rb_cFixnum, "modulo", fix_mod, 1);
- rb_define_method(rb_cFixnum, "divmod", fix_divmod, 1);
+ rb_define_method(rb_cInteger, "divmod", int_divmod, 1);
rb_define_method(rb_cInteger, "fdiv", int_fdiv, 1);
rb_define_method(rb_cInteger, "**", rb_int_pow, 1);