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

#pretty_print, #to_json

Constructor Details

#initialize(value:, location:, comments: []) ⇒ Op

Returns a new instance of Op.



6347
6348
6349
6350
6351
# File 'lib/syntax_tree/node.rb', line 6347

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



6345
6346
6347
# File 'lib/syntax_tree/node.rb', line 6345

def comments
  @comments
end

#valueObject (readonly)

String

the operator



6342
6343
6344
# File 'lib/syntax_tree/node.rb', line 6342

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



6353
6354
6355
# File 'lib/syntax_tree/node.rb', line 6353

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

#child_nodesObject Also known as: deconstruct



6357
6358
6359
# File 'lib/syntax_tree/node.rb', line 6357

def child_nodes
  []
end

#deconstruct_keys(keys) ⇒ Object



6363
6364
6365
# File 'lib/syntax_tree/node.rb', line 6363

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

#format(q) ⇒ Object



6367
6368
6369
# File 'lib/syntax_tree/node.rb', line 6367

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