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.



12563
12564
12565
12566
12567
12568
# File 'lib/syntax_tree.rb', line 12563

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



12561
12562
12563
# File 'lib/syntax_tree.rb', line 12561

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



12558
12559
12560
# File 'lib/syntax_tree.rb', line 12558

def location
  @location
end

#predicateObject (readonly)

untyped

the expression to be checked



12555
12556
12557
# File 'lib/syntax_tree.rb', line 12555

def predicate
  @predicate
end

#statementObject (readonly)

untyped

the expression to be executed



12552
12553
12554
# File 'lib/syntax_tree.rb', line 12552

def statement
  @statement
end

Instance Method Details

#child_nodesObject



12570
12571
12572
# File 'lib/syntax_tree.rb', line 12570

def child_nodes
  [statement, predicate]
end

#format(q) ⇒ Object



12574
12575
12576
# File 'lib/syntax_tree.rb', line 12574

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

#pretty_print(q) ⇒ Object



12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
# File 'lib/syntax_tree.rb', line 12578

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



12592
12593
12594
12595
12596
12597
12598
12599
12600
# File 'lib/syntax_tree.rb', line 12592

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