Class: SyntaxTree::RescueMod

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

Overview

RescueMod represents the use of the modifier form of a rescue clause.

expression rescue value

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:, value:, location:, comments: []) ⇒ RescueMod

Returns a new instance of RescueMod.



7534
7535
7536
7537
7538
7539
# File 'lib/syntax_tree/node.rb', line 7534

def initialize(statement:, value:, location:, comments: [])
  @statement = statement
  @value = value
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



7532
7533
7534
# File 'lib/syntax_tree/node.rb', line 7532

def comments
  @comments
end

#statementObject (readonly)

untyped

the expression to execute



7526
7527
7528
# File 'lib/syntax_tree/node.rb', line 7526

def statement
  @statement
end

#valueObject (readonly)

untyped

the value to use if the executed expression raises an error



7529
7530
7531
# File 'lib/syntax_tree/node.rb', line 7529

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



7541
7542
7543
# File 'lib/syntax_tree/node.rb', line 7541

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

#child_nodesObject Also known as: deconstruct



7545
7546
7547
# File 'lib/syntax_tree/node.rb', line 7545

def child_nodes
  [statement, value]
end

#deconstruct_keys(keys) ⇒ Object



7551
7552
7553
7554
7555
7556
7557
7558
# File 'lib/syntax_tree/node.rb', line 7551

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

#format(q) ⇒ Object



7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
# File 'lib/syntax_tree/node.rb', line 7560

def format(q)
  q.group(0, "begin", "end") do
    q.indent do
      q.breakable(force: true)
      q.format(statement)
    end
    q.breakable(force: true)
    q.text("rescue StandardError")
    q.indent do
      q.breakable(force: true)
      q.format(value)
    end
    q.breakable(force: true)
  end
end