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, #pretty_print, #to_json
Constructor Details
#initialize(value:, location:) ⇒ Op
Returns a new instance of Op.
7878 7879 7880 7881 7882 7883 |
# File 'lib/syntax_tree/node.rb', line 7878 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
7876 7877 7878 |
# File 'lib/syntax_tree/node.rb', line 7876 def comments @comments end |
#name ⇒ Object (readonly)
- Symbol
-
the symbol version of the value
7873 7874 7875 |
# File 'lib/syntax_tree/node.rb', line 7873 def name @name end |
#value ⇒ Object (readonly)
- String
-
the operator
7870 7871 7872 |
# File 'lib/syntax_tree/node.rb', line 7870 def value @value end |
Instance Method Details
#===(other) ⇒ Object
7911 7912 7913 |
# File 'lib/syntax_tree/node.rb', line 7911 def ===(other) other.is_a?(Op) && value === other.value end |
#accept(visitor) ⇒ Object
7885 7886 7887 |
# File 'lib/syntax_tree/node.rb', line 7885 def accept(visitor) visitor.visit_op(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7889 7890 7891 |
# File 'lib/syntax_tree/node.rb', line 7889 def child_nodes [] end |
#copy(value: nil, location: nil) ⇒ Object
7893 7894 7895 7896 7897 7898 7899 |
# File 'lib/syntax_tree/node.rb', line 7893 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
7903 7904 7905 |
# File 'lib/syntax_tree/node.rb', line 7903 def deconstruct_keys(_keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
7907 7908 7909 |
# File 'lib/syntax_tree/node.rb', line 7907 def format(q) q.text(value) end |