Class: SyntaxTree::Not

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.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.



12090
12091
12092
12093
12094
12095
# File 'lib/syntax_tree.rb', line 12090

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



12088
12089
12090
# File 'lib/syntax_tree.rb', line 12088

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



12085
12086
12087
# File 'lib/syntax_tree.rb', line 12085

def location
  @location
end

#parenthesesObject (readonly)

boolean

whether or not parentheses were used



12082
12083
12084
# File 'lib/syntax_tree.rb', line 12082

def parentheses
  @parentheses
end

#statementObject (readonly)

untyped

the statement on which to operate



12079
12080
12081
# File 'lib/syntax_tree.rb', line 12079

def statement
  @statement
end

Instance Method Details

#child_nodesObject



12097
12098
12099
# File 'lib/syntax_tree.rb', line 12097

def child_nodes
  [statement]
end

#format(q) ⇒ Object



12101
12102
12103
12104
12105
# File 'lib/syntax_tree.rb', line 12101

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

#pretty_print(q) ⇒ Object



12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
# File 'lib/syntax_tree.rb', line 12107

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



12118
12119
12120
12121
12122
12123
12124
12125
12126
# File 'lib/syntax_tree.rb', line 12118

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