diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-04-30 11:18:00 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-04-30 11:18:00 +0000 |
commit | 9fabd44735df2be72b35861bf5e6dd1364970268 (patch) | |
tree | 021f31735d8c3de7fa87e562b3aa34c7445fb5e0 /numeric.c | |
parent | 8733177dd07bf4dca25253af02dfafd3cf629874 (diff) | |
download | ruby-9fabd44735df2be72b35861bf5e6dd1364970268.tar.gz |
Define Integer#== instead of Bignum#==.
* numeric.c (int_equal): Define Integer#==.
* bignum.c (rb_big_eq): Don't define Bignum#==.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r-- | numeric.c | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -3747,11 +3747,14 @@ rb_int_pow(VALUE x, VALUE y) } /* + * 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) } } +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) 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); |