Class: Prism::RescueModifierNode

Inherits:
PrismNode
  • Object
show all
Defined in:
lib/prism/node.rb,
lib/prism/parse_result/newlines.rb,
ext/prism/api_node.c

Overview

Represents an expression modified with a rescue.

foo rescue nil
^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, expression, keyword_loc, rescue_expression) ⇒ RescueModifierNode

Initialize a new RescueModifierNode node.



15609
15610
15611
15612
15613
15614
15615
15616
15617
# File 'lib/prism/node.rb', line 15609

def initialize(source, node_id, location, flags, expression, keyword_loc, rescue_expression)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @expression = expression
  @keyword_loc = keyword_loc
  @rescue_expression = rescue_expression
end

Instance Attribute Details

#expressionObject (readonly)

attr_reader expression: Prism::node



15653
15654
15655
# File 'lib/prism/node.rb', line 15653

def expression
  @expression
end

#rescue_expressionObject (readonly)

attr_reader rescue_expression: Prism::node



15669
15670
15671
# File 'lib/prism/node.rb', line 15669

def rescue_expression
  @rescue_expression
end

Class Method Details

.typeObject

Return a symbol representation of this node type. See ‘Node::type`.



15687
15688
15689
# File 'lib/prism/node.rb', line 15687

def self.type
  :rescue_modifier_node
end

Instance Method Details

#===(other) ⇒ Object

Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.



15693
15694
15695
15696
15697
15698
# File 'lib/prism/node.rb', line 15693

def ===(other)
  other.is_a?(RescueModifierNode) &&
    (expression === other.expression) &&
    (keyword_loc.nil? == other.keyword_loc.nil?) &&
    (rescue_expression === other.rescue_expression)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



15620
15621
15622
# File 'lib/prism/node.rb', line 15620

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



15625
15626
15627
# File 'lib/prism/node.rb', line 15625

def child_nodes
  [expression, rescue_expression]
end

#comment_targetsObject

def comment_targets: () -> Array[Node | Location]



15635
15636
15637
# File 'lib/prism/node.rb', line 15635

def comment_targets
  [expression, keyword_loc, rescue_expression] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



15630
15631
15632
# File 'lib/prism/node.rb', line 15630

def compact_child_nodes
  [expression, rescue_expression]
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, expression: self.expression, keyword_loc: self.keyword_loc, rescue_expression: self.rescue_expression) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?expression: Prism::node, ?keyword_loc: Location, ?rescue_expression: Prism::node) -> RescueModifierNode



15640
15641
15642
# File 'lib/prism/node.rb', line 15640

def copy(node_id: self.node_id, location: self.location, flags: self.flags, expression: self.expression, keyword_loc: self.keyword_loc, rescue_expression: self.rescue_expression)
  RescueModifierNode.new(source, node_id, location, flags, expression, keyword_loc, rescue_expression)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, expression: Prism::node, keyword_loc: Location, rescue_expression: Prism::node }



15648
15649
15650
# File 'lib/prism/node.rb', line 15648

def deconstruct_keys(keys)
  { node_id: node_id, location: location, expression: expression, keyword_loc: keyword_loc, rescue_expression: rescue_expression }
end

#inspectObject

def inspect -> String



15677
15678
15679
# File 'lib/prism/node.rb', line 15677

def inspect
  InspectVisitor.compose(self)
end

#keywordObject

def keyword: () -> String



15672
15673
15674
# File 'lib/prism/node.rb', line 15672

def keyword
  keyword_loc.slice
end

#keyword_locObject

attr_reader keyword_loc: Location



15656
15657
15658
15659
15660
# File 'lib/prism/node.rb', line 15656

def keyword_loc
  location = @keyword_loc
  return location if location.is_a?(Location)
  @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#newline_flag!(lines) ⇒ Object

:nodoc:



115
116
117
# File 'lib/prism/parse_result/newlines.rb', line 115

def newline_flag!(lines) # :nodoc:
  expression.newline_flag!(lines)
end

#save_keyword_loc(repository) ⇒ Object

Save the keyword_loc location using the given saved source so that it can be retrieved later.



15664
15665
15666
# File 'lib/prism/node.rb', line 15664

def save_keyword_loc(repository)
  repository.enter(node_id, :keyword_loc)
end

#typeObject

Return a symbol representation of this node type. See ‘Node#type`.



15682
15683
15684
# File 'lib/prism/node.rb', line 15682

def type
  :rescue_modifier_node
end