Method: Fractify::Fraction#initialize
- Defined in:
- lib/fractify/fraction.rb
#initialize(whole_part: 0, numerator: 0, denominator: 1, string: '', numeric: false) ⇒ Fraction
Returns a new instance of Fraction.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fractify/fraction.rb', line 10 def initialize(whole_part: 0, numerator: 0, denominator: 1, string: '', numeric: false) unless string.strip.empty? to_zero! parse_fraction_string!(string) return end if numeric.is_a? Numeric convert_number!(numeric) return end raise DividingByZeroError if denominator.zero? && numerator != 0 self.whole_part = whole_part self.numerator = numerator self.denominator = denominator self.negative = false fix_negativity! simplify! to_improper! end |