Class: SyntaxTree::RescueMod

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

Overview

RescueMod represents the use of the modifier form of a rescue clause.

expression rescue value

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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



9882
9883
9884
9885
9886
9887
# File 'lib/syntax_tree.rb', line 9882

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



9880
9881
9882
# File 'lib/syntax_tree.rb', line 9880

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



9877
9878
9879
# File 'lib/syntax_tree.rb', line 9877

def location
  @location
end

#statementObject (readonly)

untyped

the expression to execute



9871
9872
9873
# File 'lib/syntax_tree.rb', line 9871

def statement
  @statement
end

#valueObject (readonly)

untyped

the value to use if the executed expression raises an error



9874
9875
9876
# File 'lib/syntax_tree.rb', line 9874

def value
  @value
end

Instance Method Details

#child_nodesObject



9889
9890
9891
# File 'lib/syntax_tree.rb', line 9889

def child_nodes
  [statement, value]
end

#format(q) ⇒ Object



9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
# File 'lib/syntax_tree.rb', line 9893

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

#pretty_print(q) ⇒ Object



9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
# File 'lib/syntax_tree.rb', line 9909

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

    q.breakable
    q.pp(statement)

    q.breakable
    q.pp(value)

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

#to_json(*opts) ⇒ Object



9923
9924
9925
9926
9927
9928
9929
9930
9931
# File 'lib/syntax_tree.rb', line 9923

def to_json(*opts)
  {
    type: :rescue_mod,
    stmt: statement,
    value: value,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end