Class: Prism::EnsureNode

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

Overview

Represents an ‘ensure` clause in a `begin` statement.

begin
  foo
ensure
^^^^^^
  bar
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, ensure_keyword_loc, statements, end_keyword_loc) ⇒ EnsureNode

Initialize a new EnsureNode node.



5753
5754
5755
5756
5757
5758
5759
5760
5761
# File 'lib/prism/node.rb', line 5753

def initialize(source, node_id, location, flags, ensure_keyword_loc, statements, end_keyword_loc)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @ensure_keyword_loc = ensure_keyword_loc
  @statements = statements
  @end_keyword_loc = end_keyword_loc
end

Instance Attribute Details

#statementsObject (readonly)

attr_reader statements: StatementsNode?



5806
5807
5808
# File 'lib/prism/node.rb', line 5806

def statements
  @statements
end

Class Method Details

.typeObject

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



5836
5837
5838
# File 'lib/prism/node.rb', line 5836

def self.type
  :ensure_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.



5842
5843
5844
5845
5846
5847
# File 'lib/prism/node.rb', line 5842

def ===(other)
  other.is_a?(EnsureNode) &&
    (ensure_keyword_loc.nil? == other.ensure_keyword_loc.nil?) &&
    (statements === other.statements) &&
    (end_keyword_loc.nil? == other.end_keyword_loc.nil?)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



5764
5765
5766
# File 'lib/prism/node.rb', line 5764

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

#child_nodesObject Also known as: deconstruct

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



5769
5770
5771
# File 'lib/prism/node.rb', line 5769

def child_nodes
  [statements]
end

#comment_targetsObject

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



5781
5782
5783
# File 'lib/prism/node.rb', line 5781

def comment_targets
  [ensure_keyword_loc, *statements, end_keyword_loc] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



5774
5775
5776
5777
5778
# File 'lib/prism/node.rb', line 5774

def compact_child_nodes
  compact = [] #: Array[Prism::node]
  compact << statements if statements
  compact
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, ensure_keyword_loc: self.ensure_keyword_loc, statements: self.statements, end_keyword_loc: self.end_keyword_loc) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?ensure_keyword_loc: Location, ?statements: StatementsNode?, ?end_keyword_loc: Location) -> EnsureNode



5786
5787
5788
# File 'lib/prism/node.rb', line 5786

def copy(node_id: self.node_id, location: self.location, flags: self.flags, ensure_keyword_loc: self.ensure_keyword_loc, statements: self.statements, end_keyword_loc: self.end_keyword_loc)
  EnsureNode.new(source, node_id, location, flags, ensure_keyword_loc, statements, end_keyword_loc)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, ensure_keyword_loc: Location, statements: StatementsNode?, end_keyword_loc: Location }



5794
5795
5796
# File 'lib/prism/node.rb', line 5794

def deconstruct_keys(keys)
  { node_id: node_id, location: location, ensure_keyword_loc: ensure_keyword_loc, statements: statements, end_keyword_loc: end_keyword_loc }
end

#end_keywordObject

def end_keyword: () -> String



5821
5822
5823
# File 'lib/prism/node.rb', line 5821

def end_keyword
  end_keyword_loc.slice
end

#end_keyword_locObject

attr_reader end_keyword_loc: Location



5809
5810
5811
5812
5813
# File 'lib/prism/node.rb', line 5809

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

#ensure_keywordObject

def ensure_keyword: () -> String



5816
5817
5818
# File 'lib/prism/node.rb', line 5816

def ensure_keyword
  ensure_keyword_loc.slice
end

#ensure_keyword_locObject

attr_reader ensure_keyword_loc: Location



5799
5800
5801
5802
5803
# File 'lib/prism/node.rb', line 5799

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

#inspectObject

def inspect -> String



5826
5827
5828
# File 'lib/prism/node.rb', line 5826

def inspect
  InspectVisitor.compose(self)
end

#typeObject

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



5831
5832
5833
# File 'lib/prism/node.rb', line 5831

def type
  :ensure_node
end