Class: SyntaxTree::Unary
Overview
Unary represents a unary method being called on an expression, as in ! or ~.
!value
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#operator ⇒ Object
readonly
- String
-
the operator being used.
-
#statement ⇒ Object
readonly
- untyped
-
the statement on which to operate.
Attributes inherited from Node
Instance Method Summary collapse
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(operator: nil, statement: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(operator:, statement:, location:) ⇒ Unary
constructor
A new instance of Unary.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(operator:, statement:, location:) ⇒ Unary
Returns a new instance of Unary.
11030 11031 11032 11033 11034 11035 |
# File 'lib/syntax_tree/node.rb', line 11030 def initialize(operator:, statement:, location:) @operator = operator @statement = statement @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
11028 11029 11030 |
# File 'lib/syntax_tree/node.rb', line 11028 def comments @comments end |
#operator ⇒ Object (readonly)
- String
-
the operator being used
11022 11023 11024 |
# File 'lib/syntax_tree/node.rb', line 11022 def operator @operator end |
#statement ⇒ Object (readonly)
- untyped
-
the statement on which to operate
11025 11026 11027 |
# File 'lib/syntax_tree/node.rb', line 11025 def statement @statement end |
Instance Method Details
#===(other) ⇒ Object
11073 11074 11075 11076 |
# File 'lib/syntax_tree/node.rb', line 11073 def ===(other) other.is_a?(Unary) && operator === other.operator && statement === other.statement end |
#accept(visitor) ⇒ Object
11037 11038 11039 |
# File 'lib/syntax_tree/node.rb', line 11037 def accept(visitor) visitor.visit_unary(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
11041 11042 11043 |
# File 'lib/syntax_tree/node.rb', line 11041 def child_nodes [statement] end |
#copy(operator: nil, statement: nil, location: nil) ⇒ Object
11045 11046 11047 11048 11049 11050 11051 11052 11053 11054 11055 |
# File 'lib/syntax_tree/node.rb', line 11045 def copy(operator: nil, statement: nil, location: nil) node = Unary.new( operator: operator || self.operator, statement: statement || self.statement, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
11059 11060 11061 11062 11063 11064 11065 11066 |
# File 'lib/syntax_tree/node.rb', line 11059 def deconstruct_keys(_keys) { operator: operator, statement: statement, location: location, comments: comments } end |
#format(q) ⇒ Object
11068 11069 11070 11071 |
# File 'lib/syntax_tree/node.rb', line 11068 def format(q) q.text(operator) q.format(statement) end |