class SyntaxTree::RangeNode
RangeNode
represents using the .. or the … operator between two expressions. Usually this is to create a range object.
1..2
Sometimes this operator is used to create a flip-flop.
if value == 5 .. value == 10 end
One of the sides of the expression may be nil, but not both.
Attributes
Op
-
the operator used for this range
Public Class Methods
Source
# File lib/syntax_tree/node.rb, line 4568 def initialize(left:, operator:, right:, location:) @left = left @operator = operator @right = right @location = location @comments = [] end
Public Instance Methods
Source
# File lib/syntax_tree/node.rb, line 4622 def ===(other) other.is_a?(RangeNode) && left === other.left && operator === other.operator && right === other.right end
Source
# File lib/syntax_tree/node.rb, line 4576 def accept(visitor) visitor.visit_range(self) end
Source
# File lib/syntax_tree/node.rb, line 4580 def child_nodes [left, right] end
Also aliased as: deconstruct
Source
# File lib/syntax_tree/node.rb, line 4584 def copy(left: nil, operator: nil, right: nil, location: nil) node = RangeNode.new( left: left || self.left, operator: operator || self.operator, right: right || self.right, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end
Source
# File lib/syntax_tree/node.rb, line 4599 def deconstruct_keys(_keys) { left: left, operator: operator, right: right, location: location, comments: comments } end
Source
# File lib/syntax_tree/node.rb, line 4609 def format(q) q.format(left) if left case q.parent when IfNode, UnlessNode q.text(" #{operator.value} ") else q.text(operator.value) end q.format(right) if right end