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.



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

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



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

def comments
  @comments
end

#consequentObject (readonly)

nil, Elsif, Else

the next clause in the chain



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

def consequent
  @consequent
end

#predicateObject (readonly)

untyped

the expression to be checked



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

def predicate
  @predicate
end

#statementsObject (readonly)

Statements

the expressions to be executed



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

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  [predicate, statements, consequent]
end

#deconstruct_keys(keys) ⇒ Object



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

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

#format(q) ⇒ Object



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

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