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

#pretty_print, #to_json

Constructor Details

#initialize(operator:, statement:, location:, comments: []) ⇒ Unary

Returns a new instance of Unary.



8228
8229
8230
8231
8232
8233
# File 'lib/syntax_tree/node.rb', line 8228

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



8226
8227
8228
# File 'lib/syntax_tree/node.rb', line 8226

def comments
  @comments
end

#operatorObject (readonly)

String

the operator being used



8220
8221
8222
# File 'lib/syntax_tree/node.rb', line 8220

def operator
  @operator
end

#statementObject (readonly)

untyped

the statement on which to operate



8223
8224
8225
# File 'lib/syntax_tree/node.rb', line 8223

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



8235
8236
8237
# File 'lib/syntax_tree/node.rb', line 8235

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

#child_nodesObject Also known as: deconstruct



8239
8240
8241
# File 'lib/syntax_tree/node.rb', line 8239

def child_nodes
  [statement]
end

#deconstruct_keys(keys) ⇒ Object



8245
8246
8247
8248
8249
8250
8251
8252
# File 'lib/syntax_tree/node.rb', line 8245

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

#format(q) ⇒ Object



8254
8255
8256
8257
# File 'lib/syntax_tree/node.rb', line 8254

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