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.



8788
8789
8790
8791
8792
8793
# File 'lib/syntax_tree/node.rb', line 8788

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



8786
8787
8788
# File 'lib/syntax_tree/node.rb', line 8786

def comments
  @comments
end

#operatorObject (readonly)

String

the operator being used



8780
8781
8782
# File 'lib/syntax_tree/node.rb', line 8780

def operator
  @operator
end

#statementObject (readonly)

untyped

the statement on which to operate



8783
8784
8785
# File 'lib/syntax_tree/node.rb', line 8783

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



8795
8796
8797
# File 'lib/syntax_tree/node.rb', line 8795

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

#child_nodesObject Also known as: deconstruct



8799
8800
8801
# File 'lib/syntax_tree/node.rb', line 8799

def child_nodes
  [statement]
end

#deconstruct_keys(keys) ⇒ Object



8805
8806
8807
8808
8809
8810
8811
8812
# File 'lib/syntax_tree/node.rb', line 8805

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

#format(q) ⇒ Object



8814
8815
8816
8817
# File 'lib/syntax_tree/node.rb', line 8814

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