Class: RubyNext::Language::Rewriters::EndlessRange
Constant Summary collapse
- NAME =
"endless-range"
- SYNTAX_PROBE =
"[0, 1][1..]"
- MIN_SUPPORTED_VERSION =
Gem::Version.new("2.6.0")
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #on_erange(node) ⇒ Object (also: #on_irange)
- #on_index(node) ⇒ Object
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_erange(node) ⇒ Object Also known as: on_irange
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ruby-next/language/rewriters/2.6/endless_range.rb', line 25 def on_erange(node) return unless node.children.last.nil? context.track! self new_end = if index_arg?(node) s(:int, -1) else s(:const, s(:const, s(:cbase), :Float), :INFINITY) end replace(node.loc.expression, "#{node.children.first.loc.expression.source}..#{unparse(new_end)}") node.updated( :irange, [ node.children.first, new_end ] ) end |
#on_index(node) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ruby-next/language/rewriters/2.6/endless_range.rb', line 11 def on_index(node) @current_index = node new_index = process(node.children.last) return unless new_index != node.children.last node.updated( nil, [ node.children.first, new_index ] ) end |