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.



6616
6617
6618
6619
6620
# File 'lib/syntax_tree/node.rb', line 6616

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



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

def comments
  @comments
end

#valueObject (readonly)

String

the operator



6611
6612
6613
# File 'lib/syntax_tree/node.rb', line 6611

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



6622
6623
6624
# File 'lib/syntax_tree/node.rb', line 6622

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

#child_nodesObject Also known as: deconstruct



6626
6627
6628
# File 'lib/syntax_tree/node.rb', line 6626

def child_nodes
  []
end

#deconstruct_keys(_keys) ⇒ Object



6632
6633
6634
# File 'lib/syntax_tree/node.rb', line 6632

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

#format(q) ⇒ Object



6636
6637
6638
# File 'lib/syntax_tree/node.rb', line 6636

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