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.



7073
7074
7075
7076
7077
7078
7079
7080
7081
# File 'lib/prism/node.rb', line 7073

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?



7139
7140
7141
# File 'lib/prism/node.rb', line 7139

def statements
  @statements
end

Class Method Details

.typeObject

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



7175
7176
7177
# File 'lib/prism/node.rb', line 7175

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.



7181
7182
7183
7184
7185
7186
# File 'lib/prism/node.rb', line 7181

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



7084
7085
7086
# File 'lib/prism/node.rb', line 7084

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



7089
7090
7091
# File 'lib/prism/node.rb', line 7089

def child_nodes
  [statements]
end

#comment_targetsObject

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



7108
7109
7110
# File 'lib/prism/node.rb', line 7108

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



7101
7102
7103
7104
7105
# File 'lib/prism/node.rb', line 7101

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



7113
7114
7115
# File 'lib/prism/node.rb', line 7113

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 }



7121
7122
7123
# File 'lib/prism/node.rb', line 7121

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

#each_child_node {|statements| ... } ⇒ Object

def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator

Yields:



7094
7095
7096
7097
7098
# File 'lib/prism/node.rb', line 7094

def each_child_node
  return to_enum(:each_child_node) unless block_given?

  yield statements if statements
end

#end_keywordObject

def end_keyword: () -> String



7160
7161
7162
# File 'lib/prism/node.rb', line 7160

def end_keyword
  end_keyword_loc.slice
end

#end_keyword_locObject

attr_reader end_keyword_loc: Location



7142
7143
7144
7145
7146
# File 'lib/prism/node.rb', line 7142

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



7155
7156
7157
# File 'lib/prism/node.rb', line 7155

def ensure_keyword
  ensure_keyword_loc.slice
end

#ensure_keyword_locObject

attr_reader ensure_keyword_loc: Location



7126
7127
7128
7129
7130
# File 'lib/prism/node.rb', line 7126

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



7165
7166
7167
# File 'lib/prism/node.rb', line 7165

def inspect
  InspectVisitor.compose(self)
end

#save_end_keyword_loc(repository) ⇒ Object

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



7150
7151
7152
# File 'lib/prism/node.rb', line 7150

def save_end_keyword_loc(repository)
  repository.enter(node_id, :end_keyword_loc)
end

#save_ensure_keyword_loc(repository) ⇒ Object

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



7134
7135
7136
# File 'lib/prism/node.rb', line 7134

def save_ensure_keyword_loc(repository)
  repository.enter(node_id, :ensure_keyword_loc)
end

#typeObject

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



7170
7171
7172
# File 'lib/prism/node.rb', line 7170

def type
  :ensure_node
end