Class: SyntaxTree::Unless

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

Overview

Unless represents the first clause in an unless chain.

unless predicate
end

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#pretty_print, #to_json

Constructor Details

#initialize(predicate:, statements:, consequent:, location:, comments: []) ⇒ Unless

Returns a new instance of Unless.



8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
# File 'lib/syntax_tree/node.rb', line 8904

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



8902
8903
8904
# File 'lib/syntax_tree/node.rb', line 8902

def comments
  @comments
end

#consequentObject (readonly)

nil, Elsif, Else

the next clause in the chain



8899
8900
8901
# File 'lib/syntax_tree/node.rb', line 8899

def consequent
  @consequent
end

#predicateObject (readonly)

untyped

the expression to be checked



8893
8894
8895
# File 'lib/syntax_tree/node.rb', line 8893

def predicate
  @predicate
end

#statementsObject (readonly)

Statements

the expressions to be executed



8896
8897
8898
# File 'lib/syntax_tree/node.rb', line 8896

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object



8918
8919
8920
# File 'lib/syntax_tree/node.rb', line 8918

def accept(visitor)
  visitor.visit_unless(self)
end

#child_nodesObject Also known as: deconstruct



8922
8923
8924
# File 'lib/syntax_tree/node.rb', line 8922

def child_nodes
  [predicate, statements, consequent]
end

#deconstruct_keys(keys) ⇒ Object



8928
8929
8930
8931
8932
8933
8934
8935
8936
# File 'lib/syntax_tree/node.rb', line 8928

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

#format(q) ⇒ Object



8938
8939
8940
# File 'lib/syntax_tree/node.rb', line 8938

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