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.



9057
9058
9059
9060
9061
9062
# File 'lib/syntax_tree/node.rb', line 9057

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



9055
9056
9057
# File 'lib/syntax_tree/node.rb', line 9055

def comments
  @comments
end

#operatorObject (readonly)

String

the operator being used



9049
9050
9051
# File 'lib/syntax_tree/node.rb', line 9049

def operator
  @operator
end

#statementObject (readonly)

untyped

the statement on which to operate



9052
9053
9054
# File 'lib/syntax_tree/node.rb', line 9052

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



9064
9065
9066
# File 'lib/syntax_tree/node.rb', line 9064

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

#child_nodesObject Also known as: deconstruct



9068
9069
9070
# File 'lib/syntax_tree/node.rb', line 9068

def child_nodes
  [statement]
end

#deconstruct_keys(_keys) ⇒ Object



9074
9075
9076
9077
9078
9079
9080
9081
# File 'lib/syntax_tree/node.rb', line 9074

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

#format(q) ⇒ Object



9083
9084
9085
9086
# File 'lib/syntax_tree/node.rb', line 9083

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