Class: SyntaxTree::Not

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

Not represents the unary not method being called on an expression.

not 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(statement:, parentheses:, location:, comments: []) ⇒ Not

Returns a new instance of Not.



8180
8181
8182
8183
8184
8185
# File 'lib/syntax_tree/node.rb', line 8180

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



8178
8179
8180
# File 'lib/syntax_tree/node.rb', line 8178

def comments
  @comments
end

#parenthesesObject (readonly)

boolean

whether or not parentheses were used



8175
8176
8177
# File 'lib/syntax_tree/node.rb', line 8175

def parentheses
  @parentheses
end

#statementObject (readonly)

untyped

the statement on which to operate



8172
8173
8174
# File 'lib/syntax_tree/node.rb', line 8172

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



8187
8188
8189
# File 'lib/syntax_tree/node.rb', line 8187

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

#child_nodesObject Also known as: deconstruct



8191
8192
8193
# File 'lib/syntax_tree/node.rb', line 8191

def child_nodes
  [statement]
end

#deconstruct_keys(keys) ⇒ Object



8197
8198
8199
8200
8201
8202
8203
8204
# File 'lib/syntax_tree/node.rb', line 8197

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

#format(q) ⇒ Object



8206
8207
8208
8209
8210
# File 'lib/syntax_tree/node.rb', line 8206

def format(q)
  q.text(parentheses ? "not(" : "not ")
  q.format(statement)
  q.text(")") if parentheses
end