Method: Rational#+
- Defined in:
- rational.c
#+(numeric) ⇒ Numeric
Performs addition.
Rational(2, 3) + Rational(2, 3) #=> (4/3)
Rational(900) + Rational(1) #=> (901/1)
Rational(-2, 9) + Rational(-9, 2) #=> (-85/18)
Rational(9, 8) + 4 #=> (41/8)
Rational(20, 9) + 9.8 #=> 12.022222222222222
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 |
# File 'rational.c', line 729 VALUE rb_rational_plus(VALUE self, VALUE other) { if (RB_INTEGER_TYPE_P(other)) { { get_dat1(self); return f_rational_new_no_reduce2(CLASS_OF(self), rb_int_plus(dat->num, rb_int_mul(other, dat->den)), dat->den); } } else if (RB_FLOAT_TYPE_P(other)) { return DBL2NUM(nurat_to_double(self) + RFLOAT_VALUE(other)); } else if (RB_TYPE_P(other, T_RATIONAL)) { { get_dat2(self, other); return f_addsub(self, adat->num, adat->den, bdat->num, bdat->den, '+'); } } else { return rb_num_coerce_bin(self, other, '+'); } } |