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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of RescueMod.



8978
8979
8980
8981
8982
8983
# File 'lib/syntax_tree/node.rb', line 8978

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



8976
8977
8978
# File 'lib/syntax_tree/node.rb', line 8976

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



8973
8974
8975
# File 'lib/syntax_tree/node.rb', line 8973

def location
  @location
end

#statementObject (readonly)

untyped

the expression to execute



8967
8968
8969
# File 'lib/syntax_tree/node.rb', line 8967

def statement
  @statement
end

#valueObject (readonly)

untyped

the value to use if the executed expression raises an error



8970
8971
8972
# File 'lib/syntax_tree/node.rb', line 8970

def value
  @value
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



8985
8986
8987
# File 'lib/syntax_tree/node.rb', line 8985

def child_nodes
  [statement, value]
end

#deconstruct_keys(keys) ⇒ Object



8991
8992
8993
8994
8995
8996
8997
8998
# File 'lib/syntax_tree/node.rb', line 8991

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

#format(q) ⇒ Object



9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
# File 'lib/syntax_tree/node.rb', line 9000

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



9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
# File 'lib/syntax_tree/node.rb', line 9016

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



9030
9031
9032
9033
9034
9035
9036
9037
9038
# File 'lib/syntax_tree/node.rb', line 9030

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