Class: SyntaxTree::UnlessMod

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



10684
10685
10686
10687
10688
10689
# File 'lib/syntax_tree/node.rb', line 10684

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



10682
10683
10684
# File 'lib/syntax_tree/node.rb', line 10682

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



10679
10680
10681
# File 'lib/syntax_tree/node.rb', line 10679

def location
  @location
end

#predicateObject (readonly)

untyped

the expression to be checked



10676
10677
10678
# File 'lib/syntax_tree/node.rb', line 10676

def predicate
  @predicate
end

#statementObject (readonly)

untyped

the expression to be executed



10673
10674
10675
# File 'lib/syntax_tree/node.rb', line 10673

def statement
  @statement
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



10691
10692
10693
# File 'lib/syntax_tree/node.rb', line 10691

def child_nodes
  [statement, predicate]
end

#deconstruct_keys(keys) ⇒ Object



10697
10698
10699
10700
10701
10702
10703
10704
# File 'lib/syntax_tree/node.rb', line 10697

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

#format(q) ⇒ Object



10706
10707
10708
# File 'lib/syntax_tree/node.rb', line 10706

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

#pretty_print(q) ⇒ Object



10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
# File 'lib/syntax_tree/node.rb', line 10710

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



10724
10725
10726
10727
10728
10729
10730
10731
10732
# File 'lib/syntax_tree/node.rb', line 10724

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