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.



8896
8897
8898
8899
8900
8901
# File 'lib/syntax_tree/node.rb', line 8896

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



8894
8895
8896
# File 'lib/syntax_tree/node.rb', line 8894

def comments
  @comments
end

#operatorObject (readonly)

String

the operator being used



8888
8889
8890
# File 'lib/syntax_tree/node.rb', line 8888

def operator
  @operator
end

#statementObject (readonly)

untyped

the statement on which to operate



8891
8892
8893
# File 'lib/syntax_tree/node.rb', line 8891

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



8903
8904
8905
# File 'lib/syntax_tree/node.rb', line 8903

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

#child_nodesObject Also known as: deconstruct



8907
8908
8909
# File 'lib/syntax_tree/node.rb', line 8907

def child_nodes
  [statement]
end

#deconstruct_keys(_keys) ⇒ Object



8913
8914
8915
8916
8917
8918
8919
8920
# File 'lib/syntax_tree/node.rb', line 8913

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

#format(q) ⇒ Object



8922
8923
8924
8925
# File 'lib/syntax_tree/node.rb', line 8922

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