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.



7744
7745
7746
7747
7748
7749
# File 'lib/syntax_tree/node.rb', line 7744

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

Instance Attribute Details

#comments ⇒ Object (readonly)

[Array[ Comment | EmbDoc ]] the comments attached to this node



7742
7743
7744
# File 'lib/syntax_tree/node.rb', line 7742

def comments
  @comments
end

#statement ⇒ Object (readonly)

[untyped] the expression to execute



7736
7737
7738
# File 'lib/syntax_tree/node.rb', line 7736

def statement
  @statement
end

#value ⇒ Object (readonly)

[untyped] the value to use if the executed expression raises an error



7739
7740
7741
# File 'lib/syntax_tree/node.rb', line 7739

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



7751
7752
7753
# File 'lib/syntax_tree/node.rb', line 7751

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

#child_nodes ⇒ Object Also known as: deconstruct



7755
7756
7757
# File 'lib/syntax_tree/node.rb', line 7755

def child_nodes
  [statement, value]
end

#deconstruct_keys(_keys) ⇒ Object



7761
7762
7763
7764
7765
7766
7767
7768
# File 'lib/syntax_tree/node.rb', line 7761

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

#format(q) ⇒ Object



7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
# File 'lib/syntax_tree/node.rb', line 7770

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