Class: Prism::EnsureNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::EnsureNode
- 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
-
#statements ⇒ Object
readonly
attr_reader statements: StatementsNode?.
Class Method Summary collapse
-
.type ⇒ Object
Return a symbol representation of this node type.
Instance Method Summary collapse
-
#===(other) ⇒ Object
Implements case-equality for the node.
-
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#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.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, ensure_keyword_loc: Location, statements: StatementsNode?, end_keyword_loc: Location }.
-
#end_keyword ⇒ Object
def end_keyword: () -> String.
-
#end_keyword_loc ⇒ Object
attr_reader end_keyword_loc: Location.
-
#ensure_keyword ⇒ Object
def ensure_keyword: () -> String.
-
#ensure_keyword_loc ⇒ Object
attr_reader ensure_keyword_loc: Location.
-
#initialize(source, node_id, location, flags, ensure_keyword_loc, statements, end_keyword_loc) ⇒ EnsureNode
constructor
Initialize a new EnsureNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#save_end_keyword_loc(repository) ⇒ Object
Save the end_keyword_loc location using the given saved source so that it can be retrieved later.
-
#save_ensure_keyword_loc(repository) ⇒ Object
Save the ensure_keyword_loc location using the given saved source so that it can be retrieved later.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(source, node_id, location, flags, ensure_keyword_loc, statements, end_keyword_loc) ⇒ EnsureNode
Initialize a new EnsureNode node.
6629 6630 6631 6632 6633 6634 6635 6636 6637 |
# File 'lib/prism/node.rb', line 6629 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
#statements ⇒ Object (readonly)
attr_reader statements: StatementsNode?
6688 6689 6690 |
# File 'lib/prism/node.rb', line 6688 def statements @statements end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
6724 6725 6726 |
# File 'lib/prism/node.rb', line 6724 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.
6730 6731 6732 6733 6734 6735 |
# File 'lib/prism/node.rb', line 6730 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
6640 6641 6642 |
# File 'lib/prism/node.rb', line 6640 def accept(visitor) visitor.visit_ensure_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
6645 6646 6647 |
# File 'lib/prism/node.rb', line 6645 def child_nodes [statements] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
6657 6658 6659 |
# File 'lib/prism/node.rb', line 6657 def comment_targets [ensure_keyword_loc, *statements, end_keyword_loc] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
6650 6651 6652 6653 6654 |
# File 'lib/prism/node.rb', line 6650 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
6662 6663 6664 |
# File 'lib/prism/node.rb', line 6662 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 }
6670 6671 6672 |
# File 'lib/prism/node.rb', line 6670 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_keyword ⇒ Object
def end_keyword: () -> String
6709 6710 6711 |
# File 'lib/prism/node.rb', line 6709 def end_keyword end_keyword_loc.slice end |
#end_keyword_loc ⇒ Object
attr_reader end_keyword_loc: Location
6691 6692 6693 6694 6695 |
# File 'lib/prism/node.rb', line 6691 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_keyword ⇒ Object
def ensure_keyword: () -> String
6704 6705 6706 |
# File 'lib/prism/node.rb', line 6704 def ensure_keyword ensure_keyword_loc.slice end |
#ensure_keyword_loc ⇒ Object
attr_reader ensure_keyword_loc: Location
6675 6676 6677 6678 6679 |
# File 'lib/prism/node.rb', line 6675 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 |
#inspect ⇒ Object
def inspect -> String
6714 6715 6716 |
# File 'lib/prism/node.rb', line 6714 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.
6699 6700 6701 |
# File 'lib/prism/node.rb', line 6699 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.
6683 6684 6685 |
# File 'lib/prism/node.rb', line 6683 def save_ensure_keyword_loc(repository) repository.enter(node_id, :ensure_keyword_loc) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
6719 6720 6721 |
# File 'lib/prism/node.rb', line 6719 def type :ensure_node end |