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

#construct_keys, #pretty_print, #to_json

Constructor Details

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

Returns a new instance of UnlessMod.



9067
9068
9069
9070
9071
9072
# File 'lib/syntax_tree/node.rb', line 9067

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



9065
9066
9067
# File 'lib/syntax_tree/node.rb', line 9065

def comments
  @comments
end

#predicateObject (readonly)

untyped

the expression to be checked



9062
9063
9064
# File 'lib/syntax_tree/node.rb', line 9062

def predicate
  @predicate
end

#statementObject (readonly)

untyped

the expression to be executed



9059
9060
9061
# File 'lib/syntax_tree/node.rb', line 9059

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



9074
9075
9076
# File 'lib/syntax_tree/node.rb', line 9074

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

#child_nodesObject Also known as: deconstruct



9078
9079
9080
# File 'lib/syntax_tree/node.rb', line 9078

def child_nodes
  [statement, predicate]
end

#deconstruct_keys(_keys) ⇒ Object



9084
9085
9086
9087
9088
9089
9090
9091
# File 'lib/syntax_tree/node.rb', line 9084

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

#format(q) ⇒ Object



9093
9094
9095
# File 'lib/syntax_tree/node.rb', line 9093

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