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

comments[R]
Array[ Comment | EmbDoc ]

the comments attached to this node

left[R]
nil | Node

the left side of the expression

operator[R]
Op

the operator used for this range

right[R]
nil | Node

the right side of the expression

Public Class Methods

new(left:, operator:, right:, location:) click to toggle source
# File lib/syntax_tree/node.rb, line 4553
def initialize(left:, operator:, right:, location:)
  @left = left
  @operator = operator
  @right = right
  @location = location
  @comments = []
end

Public Instance Methods

===(other) click to toggle source
# File lib/syntax_tree/node.rb, line 4607
def ===(other)
  other.is_a?(RangeNode) && left === other.left &&
    operator === other.operator && right === other.right
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 4561
def accept(visitor)
  visitor.visit_range(self)
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 4565
def child_nodes
  [left, right]
end
Also aliased as: deconstruct
copy(left: nil, operator: nil, right: nil, location: nil) click to toggle source
# File lib/syntax_tree/node.rb, line 4569
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
deconstruct()
Alias for: child_nodes
deconstruct_keys(_keys) click to toggle source
# File lib/syntax_tree/node.rb, line 4584
def deconstruct_keys(_keys)
  {
    left: left,
    operator: operator,
    right: right,
    location: location,
    comments: comments
  }
end
format(q) click to toggle source
# File lib/syntax_tree/node.rb, line 4594
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