Class: Prism::RationalNode

Inherits:
Node
  • Object
show all
Defined in:
lib/prism/node_ext.rb

Instance Method Summary collapse

Methods inherited from Node

#deprecated, #newline_flag!, #newline_flag?

Instance Method Details

#numericObject

Returns the value of the node as an IntegerNode or a FloatNode. This method is deprecated in favor of #value or #numerator/#denominator.



120
121
122
123
124
125
126
127
128
# File 'lib/prism/node_ext.rb', line 120

def numeric
  deprecated("value", "numerator", "denominator")

  if denominator == 1
    IntegerNode.new(source, -1, location.chop, flags, numerator)
  else
    FloatNode.new(source, -1, location.chop, 0, numerator.to_f / denominator)
  end
end

#valueObject

Returns the value of the node as a Ruby Rational.



114
115
116
# File 'lib/prism/node_ext.rb', line 114

def value
  Rational(numerator, denominator)
end