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.
29 30 31 32 33 34 35 36 |
# File 'lib/rational.rb', line 29 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.
13 14 15 16 17 18 19 20 |
# File 'lib/rational.rb', line 13 def to_simplified_s if self < 1 to_s else truncated = self.truncate "#{truncated} #{self - truncated}" end end |