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

Returns a new instance of RescueMod.



10336
10337
10338
10339
10340
10341
# File 'lib/syntax_tree.rb', line 10336

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



10334
10335
10336
# File 'lib/syntax_tree.rb', line 10334

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



10331
10332
10333
# File 'lib/syntax_tree.rb', line 10331

def location
  @location
end

#statementObject (readonly)

untyped

the expression to execute



10325
10326
10327
# File 'lib/syntax_tree.rb', line 10325

def statement
  @statement
end

#valueObject (readonly)

untyped

the value to use if the executed expression raises an error



10328
10329
10330
# File 'lib/syntax_tree.rb', line 10328

def value
  @value
end

Instance Method Details

#child_nodesObject



10343
10344
10345
# File 'lib/syntax_tree.rb', line 10343

def child_nodes
  [statement, value]
end

#format(q) ⇒ Object



10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
# File 'lib/syntax_tree.rb', line 10347

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



10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
# File 'lib/syntax_tree.rb', line 10363

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



10377
10378
10379
10380
10381
10382
10383
10384
10385
# File 'lib/syntax_tree.rb', line 10377

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