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 | untyped
-
the left side of the expression.
-
#operator ⇒ Object
readonly
- Op
-
the operator used for this range.
-
#right ⇒ Object
readonly
- nil | untyped
-
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, #pretty_print, #to_json
Constructor Details
#initialize(left:, operator:, right:, location:) ⇒ RangeNode
Returns a new instance of RangeNode.
4471 4472 4473 4474 4475 4476 4477 |
# File 'lib/syntax_tree/node.rb', line 4471 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
4469 4470 4471 |
# File 'lib/syntax_tree/node.rb', line 4469 def comments @comments end |
#left ⇒ Object (readonly)
- nil | untyped
-
the left side of the expression
4460 4461 4462 |
# File 'lib/syntax_tree/node.rb', line 4460 def left @left end |
#operator ⇒ Object (readonly)
- Op
-
the operator used for this range
4463 4464 4465 |
# File 'lib/syntax_tree/node.rb', line 4463 def operator @operator end |
#right ⇒ Object (readonly)
- nil | untyped
-
the right side of the expression
4466 4467 4468 |
# File 'lib/syntax_tree/node.rb', line 4466 def right @right end |
Instance Method Details
#===(other) ⇒ Object
4525 4526 4527 4528 |
# File 'lib/syntax_tree/node.rb', line 4525 def ===(other) other.is_a?(RangeNode) && left === other.left && operator === other.operator && right === other.right end |
#accept(visitor) ⇒ Object
4479 4480 4481 |
# File 'lib/syntax_tree/node.rb', line 4479 def accept(visitor) visitor.visit_range(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
4483 4484 4485 |
# File 'lib/syntax_tree/node.rb', line 4483 def child_nodes [left, right] end |
#copy(left: nil, operator: nil, right: nil, location: nil) ⇒ Object
4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 |
# File 'lib/syntax_tree/node.rb', line 4487 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
4502 4503 4504 4505 4506 4507 4508 4509 4510 |
# File 'lib/syntax_tree/node.rb', line 4502 def deconstruct_keys(_keys) { left: left, operator: operator, right: right, location: location, comments: comments } end |
#format(q) ⇒ Object
4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 |
# File 'lib/syntax_tree/node.rb', line 4512 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 |