Class: SyntaxTree::RangeNode
Overview
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.
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#left ⇒ Object
readonly
- nil | Node
-
the left side of the expression.
-
#operator ⇒ Object
readonly
- Op
-
the operator used for this range.
-
#right ⇒ Object
readonly
- nil | Node
-
the right side of the expression.
Attributes inherited from Node
Instance Method Summary collapse
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(left: nil, operator: nil, right: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(left:, operator:, right:, location:) ⇒ RangeNode
constructor
A new instance of RangeNode.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(left:, operator:, right:, location:) ⇒ RangeNode
Returns a new instance of RangeNode.
4568 4569 4570 4571 4572 4573 4574 |
# File 'lib/syntax_tree/node.rb', line 4568 def initialize(left:, operator:, right:, location:) @left = left @operator = operator @right = right @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
4566 4567 4568 |
# File 'lib/syntax_tree/node.rb', line 4566 def comments @comments end |
#left ⇒ Object (readonly)
- nil | Node
-
the left side of the expression
4557 4558 4559 |
# File 'lib/syntax_tree/node.rb', line 4557 def left @left end |
#operator ⇒ Object (readonly)
- Op
-
the operator used for this range
4560 4561 4562 |
# File 'lib/syntax_tree/node.rb', line 4560 def operator @operator end |
#right ⇒ Object (readonly)
- nil | Node
-
the right side of the expression
4563 4564 4565 |
# File 'lib/syntax_tree/node.rb', line 4563 def right @right end |
Instance Method Details
#===(other) ⇒ Object
4622 4623 4624 4625 |
# File 'lib/syntax_tree/node.rb', line 4622 def ===(other) other.is_a?(RangeNode) && left === other.left && operator === other.operator && right === other.right end |
#accept(visitor) ⇒ Object
4576 4577 4578 |
# File 'lib/syntax_tree/node.rb', line 4576 def accept(visitor) visitor.visit_range(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
4580 4581 4582 |
# File 'lib/syntax_tree/node.rb', line 4580 def child_nodes [left, right] end |
#copy(left: nil, operator: nil, right: nil, location: nil) ⇒ Object
4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 |
# 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 |
#deconstruct_keys(_keys) ⇒ Object
4599 4600 4601 4602 4603 4604 4605 4606 4607 |
# File 'lib/syntax_tree/node.rb', line 4599 def deconstruct_keys(_keys) { left: left, operator: operator, right: right, location: location, comments: comments } end |
#format(q) ⇒ Object
4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 |
# 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 |