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.



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

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



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

def comments
  @comments
end

#predicateObject (readonly)

untyped

the expression to be checked



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

def predicate
  @predicate
end

#statementObject (readonly)

untyped

the expression to be executed



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

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  [statement, predicate]
end

#deconstruct_keys(keys) ⇒ Object



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

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

#format(q) ⇒ Object



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

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