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.



12222
12223
12224
12225
12226
12227
# File 'lib/syntax_tree.rb', line 12222

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



12220
12221
12222
# File 'lib/syntax_tree.rb', line 12220

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



12217
12218
12219
# File 'lib/syntax_tree.rb', line 12217

def location
  @location
end

#parenthesesObject (readonly)

boolean

whether or not parentheses were used



12214
12215
12216
# File 'lib/syntax_tree.rb', line 12214

def parentheses
  @parentheses
end

#statementObject (readonly)

untyped

the statement on which to operate



12211
12212
12213
# File 'lib/syntax_tree.rb', line 12211

def statement
  @statement
end

Instance Method Details

#child_nodesObject



12229
12230
12231
# File 'lib/syntax_tree.rb', line 12229

def child_nodes
  [statement]
end

#format(q) ⇒ Object



12233
12234
12235
12236
12237
# File 'lib/syntax_tree.rb', line 12233

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

#pretty_print(q) ⇒ Object



12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
# File 'lib/syntax_tree.rb', line 12239

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



12250
12251
12252
12253
12254
12255
12256
12257
12258
# File 'lib/syntax_tree.rb', line 12250

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