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



6793
6794
6795
6796
6797
6798
# File 'lib/syntax_tree/node.rb', line 6793

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



6791
6792
6793
# File 'lib/syntax_tree/node.rb', line 6791

def comments
  @comments
end

#nameObject (readonly)

Symbol

the symbol version of the value



6788
6789
6790
# File 'lib/syntax_tree/node.rb', line 6788

def name
  @name
end

#valueObject (readonly)

String

the operator



6785
6786
6787
# File 'lib/syntax_tree/node.rb', line 6785

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



6800
6801
6802
# File 'lib/syntax_tree/node.rb', line 6800

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

#child_nodesObject Also known as: deconstruct



6804
6805
6806
# File 'lib/syntax_tree/node.rb', line 6804

def child_nodes
  []
end

#deconstruct_keys(_keys) ⇒ Object



6810
6811
6812
# File 'lib/syntax_tree/node.rb', line 6810

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

#format(q) ⇒ Object



6814
6815
6816
# File 'lib/syntax_tree/node.rb', line 6814

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