Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/fraction_tree/extensions.rb
Instance Method Summary collapse
-
#to_node ⇒ FractionTree::Node
String Stern-Brocot decoded.
Instance Method Details
#to_node ⇒ FractionTree::Node
Returns string Stern-Brocot decoded.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/fraction_tree/extensions.rb', line 6 def to_node if self.include?(".") number = self.to_d numerator, denominator = number.numerator, number.denominator elsif self.include?("/") (numerator, denominator) = self.split("/").map(&:to_i) else number = self.to_r numerator, denominator = number.numerator, number.denominator end number = denominator.zero? ? Float::INFINITY : Rational(numerator, denominator) FractionTree::Node.new(number) end |