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:) ⇒ RescueMod



9402
9403
9404
9405
9406
9407
# File 'lib/syntax_tree/node.rb', line 9402

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



9400
9401
9402
# File 'lib/syntax_tree/node.rb', line 9400

def comments
  @comments
end

#statementObject (readonly)

untyped

the expression to execute



9394
9395
9396
# File 'lib/syntax_tree/node.rb', line 9394

def statement
  @statement
end

#valueObject (readonly)

untyped

the value to use if the executed expression raises an error



9397
9398
9399
# File 'lib/syntax_tree/node.rb', line 9397

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



9458
9459
9460
9461
# File 'lib/syntax_tree/node.rb', line 9458

def ===(other)
  other.is_a?(RescueMod) && statement === other.statement &&
    value === other.value
end

#accept(visitor) ⇒ Object



9409
9410
9411
# File 'lib/syntax_tree/node.rb', line 9409

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

#child_nodesObject Also known as: deconstruct



9413
9414
9415
# File 'lib/syntax_tree/node.rb', line 9413

def child_nodes
  [statement, value]
end

#copy(statement: nil, value: nil, location: nil) ⇒ Object



9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
# File 'lib/syntax_tree/node.rb', line 9417

def copy(statement: nil, value: nil, location: nil)
  node =
    RescueMod.new(
      statement: statement || self.statement,
      value: value || self.value,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end

#deconstruct_keys(_keys) ⇒ Object



9431
9432
9433
9434
9435
9436
9437
9438
# File 'lib/syntax_tree/node.rb', line 9431

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

#format(q) ⇒ Object



9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
# File 'lib/syntax_tree/node.rb', line 9440

def format(q)
  q.text("begin")
  q.group do
    q.indent do
      q.breakable_force
      q.format(statement)
    end
    q.breakable_force
    q.text("rescue StandardError")
    q.indent do
      q.breakable_force
      q.format(value)
    end
    q.breakable_force
  end
  q.text("end")
end