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.



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

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



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

def comments
  @comments
end

#statementObject (readonly)

untyped

the expression to execute



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

def statement
  @statement
end

#valueObject (readonly)

untyped

the value to use if the executed expression raises an error



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

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  [statement, value]
end

#deconstruct_keys(keys) ⇒ Object



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

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

#format(q) ⇒ Object



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

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