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.
10995 10996 10997 10998 10999 11000 |
# File 'lib/syntax_tree/node.rb', line 10995 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
10993 10994 10995 |
# File 'lib/syntax_tree/node.rb', line 10993 def comments @comments end |
#operator ⇒ Object (readonly)
- String
-
the operator being used
10987 10988 10989 |
# File 'lib/syntax_tree/node.rb', line 10987 def operator @operator end |
#statement ⇒ Object (readonly)
- untyped
-
the statement on which to operate
10990 10991 10992 |
# File 'lib/syntax_tree/node.rb', line 10990 def statement @statement end |
Instance Method Details
#===(other) ⇒ Object
11038 11039 11040 11041 |
# File 'lib/syntax_tree/node.rb', line 11038 def ===(other) other.is_a?(Unary) && operator === other.operator && statement === other.statement end |
#accept(visitor) ⇒ Object
11002 11003 11004 |
# File 'lib/syntax_tree/node.rb', line 11002 def accept(visitor) visitor.visit_unary(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
11006 11007 11008 |
# File 'lib/syntax_tree/node.rb', line 11006 def child_nodes [statement] end |
#copy(operator: nil, statement: nil, location: nil) ⇒ Object
11010 11011 11012 11013 11014 11015 11016 11017 11018 11019 11020 |
# File 'lib/syntax_tree/node.rb', line 11010 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
11024 11025 11026 11027 11028 11029 11030 11031 |
# File 'lib/syntax_tree/node.rb', line 11024 def deconstruct_keys(_keys) { operator: operator, statement: statement, location: location, comments: comments } end |
#format(q) ⇒ Object
11033 11034 11035 11036 |
# File 'lib/syntax_tree/node.rb', line 11033 def format(q) q.text(operator) q.format(statement) end |