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

#construct_keys, #pretty_print, #to_json

Constructor Details

#initialize(statement:, value:, location:, comments: []) ⇒ RescueMod

Returns a new instance of RescueMod.



7811
7812
7813
7814
7815
7816
# File 'lib/syntax_tree/node.rb', line 7811

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



7809
7810
7811
# File 'lib/syntax_tree/node.rb', line 7809

def comments
  @comments
end

#statementObject (readonly)

untyped

the expression to execute



7803
7804
7805
# File 'lib/syntax_tree/node.rb', line 7803

def statement
  @statement
end

#valueObject (readonly)

untyped

the value to use if the executed expression raises an error



7806
7807
7808
# File 'lib/syntax_tree/node.rb', line 7806

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



7818
7819
7820
# File 'lib/syntax_tree/node.rb', line 7818

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

#child_nodesObject Also known as: deconstruct



7822
7823
7824
# File 'lib/syntax_tree/node.rb', line 7822

def child_nodes
  [statement, value]
end

#deconstruct_keys(_keys) ⇒ Object



7828
7829
7830
7831
7832
7833
7834
7835
# File 'lib/syntax_tree/node.rb', line 7828

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

#format(q) ⇒ Object



7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
# File 'lib/syntax_tree/node.rb', line 7837

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