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.



8973
8974
8975
8976
8977
8978
# File 'lib/syntax_tree/node.rb', line 8973

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



8971
8972
8973
# File 'lib/syntax_tree/node.rb', line 8971

def comments
  @comments
end

#operatorObject (readonly)

String

the operator being used



8965
8966
8967
# File 'lib/syntax_tree/node.rb', line 8965

def operator
  @operator
end

#statementObject (readonly)

untyped

the statement on which to operate



8968
8969
8970
# File 'lib/syntax_tree/node.rb', line 8968

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



8980
8981
8982
# File 'lib/syntax_tree/node.rb', line 8980

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

#child_nodesObject Also known as: deconstruct



8984
8985
8986
# File 'lib/syntax_tree/node.rb', line 8984

def child_nodes
  [statement]
end

#deconstruct_keys(_keys) ⇒ Object



8990
8991
8992
8993
8994
8995
8996
8997
# File 'lib/syntax_tree/node.rb', line 8990

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

#format(q) ⇒ Object



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

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