Class: SyntaxTree::UnlessMod

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

Overview

UnlessMod represents the modifier form of an unless statement.

expression unless predicate

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(statement:, predicate:, location:, comments: []) ⇒ UnlessMod

Returns a new instance of UnlessMod.



12431
12432
12433
12434
12435
12436
# File 'lib/syntax_tree.rb', line 12431

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



12429
12430
12431
# File 'lib/syntax_tree.rb', line 12429

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



12426
12427
12428
# File 'lib/syntax_tree.rb', line 12426

def location
  @location
end

#predicateObject (readonly)

untyped

the expression to be checked



12423
12424
12425
# File 'lib/syntax_tree.rb', line 12423

def predicate
  @predicate
end

#statementObject (readonly)

untyped

the expression to be executed



12420
12421
12422
# File 'lib/syntax_tree.rb', line 12420

def statement
  @statement
end

Instance Method Details

#child_nodesObject



12438
12439
12440
# File 'lib/syntax_tree.rb', line 12438

def child_nodes
  [statement, predicate]
end

#format(q) ⇒ Object



12442
12443
12444
# File 'lib/syntax_tree.rb', line 12442

def format(q)
  ConditionalModFormatter.new("unless", self).format(q)
end

#pretty_print(q) ⇒ Object



12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
# File 'lib/syntax_tree.rb', line 12446

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

    q.breakable
    q.pp(statement)

    q.breakable
    q.pp(predicate)

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

#to_json(*opts) ⇒ Object



12460
12461
12462
12463
12464
12465
12466
12467
12468
# File 'lib/syntax_tree.rb', line 12460

def to_json(*opts)
  {
    type: :unless_mod,
    stmt: statement,
    pred: predicate,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end