Class: SyntaxTree::RescueEx

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

Overview

RescueEx represents the list of exceptions being rescued in a rescue clause.

begin
rescue Exception => exception
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exceptions:, variable:, location:, comments: []) ⇒ RescueEx

Returns a new instance of RescueEx.



9652
9653
9654
9655
9656
9657
# File 'lib/syntax_tree.rb', line 9652

def initialize(exceptions:, variable:, location:, comments: [])
  @exceptions = exceptions
  @variable = variable
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



9650
9651
9652
# File 'lib/syntax_tree.rb', line 9650

def comments
  @comments
end

#exceptionsObject (readonly)

untyped

the list of exceptions being rescued



9640
9641
9642
# File 'lib/syntax_tree.rb', line 9640

def exceptions
  @exceptions
end

#locationObject (readonly)

Location

the location of this node



9647
9648
9649
# File 'lib/syntax_tree.rb', line 9647

def location
  @location
end

#variableObject (readonly)

nil | Field | VarField

the expression being used to capture the raised

exception



9644
9645
9646
# File 'lib/syntax_tree.rb', line 9644

def variable
  @variable
end

Instance Method Details

#child_nodesObject



9659
9660
9661
# File 'lib/syntax_tree.rb', line 9659

def child_nodes
  [*exceptions, variable]
end

#format(q) ⇒ Object



9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
# File 'lib/syntax_tree.rb', line 9663

def format(q)
  q.group do
    if exceptions
      q.text(" ")
      q.format(exceptions)
    end

    if variable
      q.text(" => ")
      q.format(variable)
    end
  end
end

#pretty_print(q) ⇒ Object



9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
# File 'lib/syntax_tree.rb', line 9677

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("rescue_ex")

    q.breakable
    q.pp(exceptions)

    q.breakable
    q.pp(variable)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



9691
9692
9693
9694
9695
9696
9697
9698
9699
# File 'lib/syntax_tree.rb', line 9691

def to_json(*opts)
  {
    type: :rescue_ex,
    extns: exceptions,
    var: variable,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end