Class: SyntaxTree::Dot3

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

Overview

Dot3 represents using the … operator between two expressions. Usually this is to create a range object. It’s effectively the same event as the Dot2 node but with this operator you’re asking Ruby to omit the final value.

1...2

Like Dot2 it can also be 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: []) ⇒ Dot3

Returns a new instance of Dot3.



3868
3869
3870
3871
3872
3873
# File 'lib/syntax_tree/node.rb', line 3868

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



3866
3867
3868
# File 'lib/syntax_tree/node.rb', line 3866

def comments
  @comments
end

#leftObject (readonly)

nil | untyped

the left side of the expression



3860
3861
3862
# File 'lib/syntax_tree/node.rb', line 3860

def left
  @left
end

#rightObject (readonly)

nil | untyped

the right side of the expression



3863
3864
3865
# File 'lib/syntax_tree/node.rb', line 3863

def right
  @right
end

Instance Method Details

#accept(visitor) ⇒ Object



3875
3876
3877
# File 'lib/syntax_tree/node.rb', line 3875

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

#child_nodesObject Also known as: deconstruct



3879
3880
3881
# File 'lib/syntax_tree/node.rb', line 3879

def child_nodes
  [left, right]
end

#deconstruct_keys(_keys) ⇒ Object



3885
3886
3887
# File 'lib/syntax_tree/node.rb', line 3885

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

#format(q) ⇒ Object



3889
3890
3891
# File 'lib/syntax_tree/node.rb', line 3889

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