Class: Rational
- Inherits:
-
Object
- Object
- Rational
- Defined in:
- lib/rational.rb
Overview
Monkey patch to add some formatting methods to Rational.
Instance Method Summary collapse
-
#to_simplified_a ⇒ Array
Converts Rational to Array.
-
#to_simplified_s ⇒ String
Converts Rational to String.
Instance Method Details
#to_simplified_a ⇒ Array
Converts Rational to Array
If Rational is an improper fraction, removes the integer part to convert to a mixed fraction.
31 32 33 34 35 36 37 38 |
# File 'lib/rational.rb', line 31 def to_simplified_a if self < 1 to_s else truncated = self.truncate [truncated, (self - truncated)] end end |
#to_simplified_s ⇒ String
Converts Rational to String
If Rational is an improper fraction, removes the integer part to convert to a mixed fraction.
15 16 17 18 19 20 21 22 |
# File 'lib/rational.rb', line 15 def to_simplified_s if self < 1 to_s else truncated = self.truncate "#{truncated} #{self - truncated}" end end |