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

Returns a new instance of Unary.



9007
9008
9009
9010
9011
9012
# File 'lib/syntax_tree/node.rb', line 9007

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

Instance Attribute Details

#comments ⇒ Object (readonly)

[Array[ Comment | EmbDoc ]] the comments attached to this node



9005
9006
9007
# File 'lib/syntax_tree/node.rb', line 9005

def comments
  @comments
end

#operator ⇒ Object (readonly)

[String] the operator being used



8999
9000
9001
# File 'lib/syntax_tree/node.rb', line 8999

def operator
  @operator
end

#statement ⇒ Object (readonly)

[untyped] the statement on which to operate



9002
9003
9004
# File 'lib/syntax_tree/node.rb', line 9002

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



9014
9015
9016
# File 'lib/syntax_tree/node.rb', line 9014

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

#child_nodes ⇒ Object Also known as: deconstruct



9018
9019
9020
# File 'lib/syntax_tree/node.rb', line 9018

def child_nodes
  [statement]
end

#deconstruct_keys(_keys) ⇒ Object



9024
9025
9026
9027
9028
9029
9030
9031
# File 'lib/syntax_tree/node.rb', line 9024

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

#format(q) ⇒ Object



9033
9034
9035
9036
# File 'lib/syntax_tree/node.rb', line 9033

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