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.



8007
8008
8009
8010
8011
8012
# File 'lib/syntax_tree/node.rb', line 8007

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



8005
8006
8007
# File 'lib/syntax_tree/node.rb', line 8005

def comments
  @comments
end

#statementObject (readonly)

untyped

the expression to execute



7999
8000
8001
# File 'lib/syntax_tree/node.rb', line 7999

def statement
  @statement
end

#valueObject (readonly)

untyped

the value to use if the executed expression raises an error



8002
8003
8004
# File 'lib/syntax_tree/node.rb', line 8002

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



8014
8015
8016
# File 'lib/syntax_tree/node.rb', line 8014

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

#child_nodesObject Also known as: deconstruct



8018
8019
8020
# File 'lib/syntax_tree/node.rb', line 8018

def child_nodes
  [statement, value]
end

#deconstruct_keys(_keys) ⇒ Object



8024
8025
8026
8027
8028
8029
8030
8031
# File 'lib/syntax_tree/node.rb', line 8024

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

#format(q) ⇒ Object



8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
# File 'lib/syntax_tree/node.rb', line 8033

def format(q)
  q.text("begin")
  q.group do
    q.indent do
      q.breakable_force
      q.format(statement)
    end
    q.breakable_force
    q.text("rescue StandardError")
    q.indent do
      q.breakable_force
      q.format(value)
    end
    q.breakable_force
  end
  q.text("end")
end