instance method
Integer#+
(::BigDecimal) -> ::BigDecimal
(::Integer) -> ::Integer
(::Float) -> ::Float
(::Rational) -> ::Rational
(::Complex) -> ::Complex
self + other → numeric
numeric.c
View on GitHub ↗
VALUE
rb_int_plus(VALUE x, VALUE y)
{
if (FIXNUM_P(x)) {
return fix_plus(x, y);
}
else if (RB_BIGNUM_TYPE_P(x)) {
return rb_big_plus(x, y);
}
return rb_num_coerce_bin(x, y, '+');
}
Returns the sum of self and other:
Example
1 + 1 # => 2 1 + -1 # => 0 1 + 0 # => 1 1 + -2 # => -1 1 + Complex(1, 0) # => (2+0i) 1 + Rational(1, 1) # => (2/1)
For a computation involving Floats, the result may be inexact (see Float#+):
Example
1 + 3.14 # => 4.140000000000001