Class: SyntaxTree::Unary

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

Unary represents a unary method being called on an expression, as in ! or ~.

!value

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(operator:, statement:, location:, comments: []) ⇒ Unary



9291
9292
9293
9294
9295
9296
# File 'lib/syntax_tree/node.rb', line 9291

def initialize(operator:, statement:, location:, comments: [])
  @operator = operator
  @statement = statement
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



9289
9290
9291
# File 'lib/syntax_tree/node.rb', line 9289

def comments
  @comments
end

#operatorObject (readonly)

String

the operator being used



9283
9284
9285
# File 'lib/syntax_tree/node.rb', line 9283

def operator
  @operator
end

#statementObject (readonly)

untyped

the statement on which to operate



9286
9287
9288
# File 'lib/syntax_tree/node.rb', line 9286

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



9298
9299
9300
# File 'lib/syntax_tree/node.rb', line 9298

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

#child_nodesObject Also known as: deconstruct



9302
9303
9304
# File 'lib/syntax_tree/node.rb', line 9302

def child_nodes
  [statement]
end

#deconstruct_keys(_keys) ⇒ Object



9308
9309
9310
9311
9312
9313
9314
9315
# File 'lib/syntax_tree/node.rb', line 9308

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

#format(q) ⇒ Object



9317
9318
9319
9320
# File 'lib/syntax_tree/node.rb', line 9317

def format(q)
  q.text(operator)
  q.format(statement)
end