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

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#pretty_print, #to_json

Constructor Details

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

Returns a new instance of UnlessMod.



8957
8958
8959
8960
8961
8962
# File 'lib/syntax_tree/node.rb', line 8957

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



8955
8956
8957
# File 'lib/syntax_tree/node.rb', line 8955

def comments
  @comments
end

#predicateObject (readonly)

untyped

the expression to be checked



8952
8953
8954
# File 'lib/syntax_tree/node.rb', line 8952

def predicate
  @predicate
end

#statementObject (readonly)

untyped

the expression to be executed



8949
8950
8951
# File 'lib/syntax_tree/node.rb', line 8949

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



8964
8965
8966
# File 'lib/syntax_tree/node.rb', line 8964

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

#child_nodesObject Also known as: deconstruct



8968
8969
8970
# File 'lib/syntax_tree/node.rb', line 8968

def child_nodes
  [statement, predicate]
end

#deconstruct_keys(keys) ⇒ Object



8974
8975
8976
8977
8978
8979
8980
8981
# File 'lib/syntax_tree/node.rb', line 8974

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

#format(q) ⇒ Object



8983
8984
8985
# File 'lib/syntax_tree/node.rb', line 8983

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