Class: SyntaxTree::Op
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
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#name ⇒ Object
readonly
- Symbol
-
the symbol version of the value.
-
#value ⇒ Object
readonly
- String
-
the operator.
Attributes inherited from Node
Instance Method Summary collapse
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(value: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:) ⇒ Op
constructor
A new instance of Op.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(value:, location:) ⇒ Op
Returns a new instance of Op.
8010 8011 8012 8013 8014 8015 |
# File 'lib/syntax_tree/node.rb', line 8010 def initialize(value:, location:) @value = value @name = value.to_sym @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
8008 8009 8010 |
# File 'lib/syntax_tree/node.rb', line 8008 def comments @comments end |
#name ⇒ Object (readonly)
- Symbol
-
the symbol version of the value
8005 8006 8007 |
# File 'lib/syntax_tree/node.rb', line 8005 def name @name end |
#value ⇒ Object (readonly)
- String
-
the operator
8002 8003 8004 |
# File 'lib/syntax_tree/node.rb', line 8002 def value @value end |
Instance Method Details
#===(other) ⇒ Object
8043 8044 8045 |
# File 'lib/syntax_tree/node.rb', line 8043 def ===(other) other.is_a?(Op) && value === other.value end |
#accept(visitor) ⇒ Object
8017 8018 8019 |
# File 'lib/syntax_tree/node.rb', line 8017 def accept(visitor) visitor.visit_op(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
8021 8022 8023 |
# File 'lib/syntax_tree/node.rb', line 8021 def child_nodes [] end |
#copy(value: nil, location: nil) ⇒ Object
8025 8026 8027 8028 8029 8030 8031 |
# File 'lib/syntax_tree/node.rb', line 8025 def copy(value: nil, location: nil) node = Op.new(value: value || self.value, location: location || self.location) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
8035 8036 8037 |
# File 'lib/syntax_tree/node.rb', line 8035 def deconstruct_keys(_keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
8039 8040 8041 |
# File 'lib/syntax_tree/node.rb', line 8039 def format(q) q.text(value) end |