Class: SyntaxTree::Dot2

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

Dot2 represents using 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

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#pretty_print, #to_json

Constructor Details

#initialize(left:, right:, location:, comments: []) ⇒ Dot2

Returns a new instance of Dot2.



3715
3716
3717
3718
3719
3720
# File 'lib/syntax_tree/node.rb', line 3715

def initialize(left:, right:, location:, comments: [])
  @left = left
  @right = right
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



3713
3714
3715
# File 'lib/syntax_tree/node.rb', line 3713

def comments
  @comments
end

#leftObject (readonly)

nil | untyped

the left side of the expression



3707
3708
3709
# File 'lib/syntax_tree/node.rb', line 3707

def left
  @left
end

#rightObject (readonly)

nil | untyped

the right side of the expression



3710
3711
3712
# File 'lib/syntax_tree/node.rb', line 3710

def right
  @right
end

Instance Method Details

#accept(visitor) ⇒ Object



3722
3723
3724
# File 'lib/syntax_tree/node.rb', line 3722

def accept(visitor)
  visitor.visit_dot2(self)
end

#child_nodesObject Also known as: deconstruct



3726
3727
3728
# File 'lib/syntax_tree/node.rb', line 3726

def child_nodes
  [left, right]
end

#deconstruct_keys(keys) ⇒ Object



3732
3733
3734
# File 'lib/syntax_tree/node.rb', line 3732

def deconstruct_keys(keys)
  { left: left, right: right, location: location, comments: comments }
end

#format(q) ⇒ Object



3736
3737
3738
# File 'lib/syntax_tree/node.rb', line 3736

def format(q)
  DotFormatter.new("..", self).format(q)
end