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

Constructor Details

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

Returns a new instance of Not.



9972
9973
9974
9975
9976
9977
# File 'lib/syntax_tree/node.rb', line 9972

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



9970
9971
9972
# File 'lib/syntax_tree/node.rb', line 9970

def comments
  @comments
end

#parenthesesObject (readonly)

boolean

whether or not parentheses were used



9967
9968
9969
# File 'lib/syntax_tree/node.rb', line 9967

def parentheses
  @parentheses
end

#statementObject (readonly)

untyped

the statement on which to operate



9964
9965
9966
# File 'lib/syntax_tree/node.rb', line 9964

def statement
  @statement
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



9979
9980
9981
# File 'lib/syntax_tree/node.rb', line 9979

def child_nodes
  [statement]
end

#deconstruct_keys(keys) ⇒ Object



9985
9986
9987
9988
9989
9990
9991
9992
# File 'lib/syntax_tree/node.rb', line 9985

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

#format(q) ⇒ Object



9994
9995
9996
9997
9998
# File 'lib/syntax_tree/node.rb', line 9994

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

#pretty_print(q) ⇒ Object



10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
# File 'lib/syntax_tree/node.rb', line 10000

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



10011
10012
10013
10014
10015
10016
10017
10018
10019
# File 'lib/syntax_tree/node.rb', line 10011

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