Class: SyntaxTree::Op

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

Overview

Op represents an operator literal in the source.

1 + 2

In the example above, the Op node represents the + operator.

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(value:, location:, comments: []) ⇒ Op

Returns a new instance of Op.



6599
6600
6601
6602
6603
# File 'lib/syntax_tree/node.rb', line 6599

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



6597
6598
6599
# File 'lib/syntax_tree/node.rb', line 6597

def comments
  @comments
end

#valueObject (readonly)

String

the operator



6594
6595
6596
# File 'lib/syntax_tree/node.rb', line 6594

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



6605
6606
6607
# File 'lib/syntax_tree/node.rb', line 6605

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

#child_nodesObject Also known as: deconstruct



6609
6610
6611
# File 'lib/syntax_tree/node.rb', line 6609

def child_nodes
  []
end

#deconstruct_keys(_keys) ⇒ Object



6615
6616
6617
# File 'lib/syntax_tree/node.rb', line 6615

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

#format(q) ⇒ Object



6619
6620
6621
# File 'lib/syntax_tree/node.rb', line 6619

def format(q)
  q.text(value)
end