Class: RubyNext::Language::Rewriters::NumericLiterals
Constant Summary collapse
- NAME =
"numeric-literals"
- SYNTAX_PROBE =
"2i + 1/2r"
- MIN_SUPPORTED_VERSION =
Gem::Version.new("2.1.0")
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
Methods inherited from Abstract
ast?, #initialize, text?, unsupported_syntax?, unsupported_version?
Constructor Details
This class inherits a constructor from RubyNext::Language::Rewriters::Base
Instance Method Details
#on_complex(node) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ruby-next/language/rewriters/2.1/numeric_literals.rb', line 27 def on_complex(node) context.track! self val = node.children.first s(:send, nil, :Complex, s(:int, val.real), s(:int, val.imaginary)).tap do |new_node| replace(node.loc.expression, new_node) end end |
#on_rational(node) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ruby-next/language/rewriters/2.1/numeric_literals.rb', line 13 def on_rational(node) context.track! self val = node.children.first parts = [s(:int, val.numerator)] parts << s(:int, val.denominator) unless val.denominator == 1 s(:send, nil, :Rational, *parts).tap do |new_node| replace(node.loc.expression, new_node) end end |