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

Instance Method Summary collapse

Constructor Details

#initialize(statement:, parentheses:, location:, comments: []) ⇒ Not

Returns a new instance of Not.



10380
10381
10382
10383
10384
10385
# File 'lib/syntax_tree/node.rb', line 10380

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



10378
10379
10380
# File 'lib/syntax_tree/node.rb', line 10378

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



10375
10376
10377
# File 'lib/syntax_tree/node.rb', line 10375

def location
  @location
end

#parenthesesObject (readonly)

boolean

whether or not parentheses were used



10372
10373
10374
# File 'lib/syntax_tree/node.rb', line 10372

def parentheses
  @parentheses
end

#statementObject (readonly)

untyped

the statement on which to operate



10369
10370
10371
# File 'lib/syntax_tree/node.rb', line 10369

def statement
  @statement
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



10387
10388
10389
# File 'lib/syntax_tree/node.rb', line 10387

def child_nodes
  [statement]
end

#deconstruct_keys(keys) ⇒ Object



10393
10394
10395
10396
10397
10398
10399
10400
# File 'lib/syntax_tree/node.rb', line 10393

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

#format(q) ⇒ Object



10402
10403
10404
10405
10406
# File 'lib/syntax_tree/node.rb', line 10402

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

#pretty_print(q) ⇒ Object



10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
# File 'lib/syntax_tree/node.rb', line 10408

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("not")

    q.breakable
    q.pp(statement)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



10419
10420
10421
10422
10423
10424
10425
10426
10427
# File 'lib/syntax_tree/node.rb', line 10419

def to_json(*opts)
  {
    type: :not,
    value: statement,
    paren: parentheses,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end