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.



6549
6550
6551
6552
6553
# File 'lib/syntax_tree/node.rb', line 6549

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

Instance Attribute Details

#comments ⇒ Object (readonly)

[Array[ Comment | EmbDoc ]] the comments attached to this node



6547
6548
6549
# File 'lib/syntax_tree/node.rb', line 6547

def comments
  @comments
end

#value ⇒ Object (readonly)

[String] the operator



6544
6545
6546
# File 'lib/syntax_tree/node.rb', line 6544

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



6555
6556
6557
# File 'lib/syntax_tree/node.rb', line 6555

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

#child_nodes ⇒ Object Also known as: deconstruct



6559
6560
6561
# File 'lib/syntax_tree/node.rb', line 6559

def child_nodes
  []
end

#deconstruct_keys(_keys) ⇒ Object



6565
6566
6567
# File 'lib/syntax_tree/node.rb', line 6565

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

#format(q) ⇒ Object



6569
6570
6571
# File 'lib/syntax_tree/node.rb', line 6569

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