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

#construct_keys, #pretty_print, #to_json

Constructor Details

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

Returns a new instance of Dot2.



3918
3919
3920
3921
3922
3923
# File 'lib/syntax_tree/node.rb', line 3918

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



3916
3917
3918
# File 'lib/syntax_tree/node.rb', line 3916

def comments
  @comments
end

#leftObject (readonly)

nil | untyped

the left side of the expression



3910
3911
3912
# File 'lib/syntax_tree/node.rb', line 3910

def left
  @left
end

#rightObject (readonly)

nil | untyped

the right side of the expression



3913
3914
3915
# File 'lib/syntax_tree/node.rb', line 3913

def right
  @right
end

Instance Method Details

#accept(visitor) ⇒ Object



3925
3926
3927
# File 'lib/syntax_tree/node.rb', line 3925

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

#child_nodesObject Also known as: deconstruct



3929
3930
3931
# File 'lib/syntax_tree/node.rb', line 3929

def child_nodes
  [left, right]
end

#deconstruct_keys(_keys) ⇒ Object



3935
3936
3937
# File 'lib/syntax_tree/node.rb', line 3935

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

#format(q) ⇒ Object



3939
3940
3941
# File 'lib/syntax_tree/node.rb', line 3939

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