Class: Prism::ElseNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::ElseNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents an ‘else` clause in a `case`, `if`, or `unless` statement.
if a then b else c 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, else_keyword_loc: self.else_keyword_loc, statements: self.statements, end_keyword_loc: self.end_keyword_loc) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?else_keyword_loc: Location, ?statements: StatementsNode?, ?end_keyword_loc: Location?) -> ElseNode.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, else_keyword_loc: Location, statements: StatementsNode?, end_keyword_loc: Location? }.
-
#else_keyword ⇒ Object
def else_keyword: () -> String.
-
#else_keyword_loc ⇒ Object
attr_reader else_keyword_loc: Location.
-
#end_keyword ⇒ Object
def end_keyword: () -> String?.
-
#end_keyword_loc ⇒ Object
attr_reader end_keyword_loc: Location?.
-
#initialize(source, node_id, location, flags, else_keyword_loc, statements, end_keyword_loc) ⇒ ElseNode
constructor
Initialize a new ElseNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#save_else_keyword_loc(repository) ⇒ Object
Save the else_keyword_loc location using the given saved source so that it can be retrieved later.
-
#save_end_keyword_loc(repository) ⇒ Object
Save the end_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, else_keyword_loc, statements, end_keyword_loc) ⇒ ElseNode
Initialize a new ElseNode node.
6296 6297 6298 6299 6300 6301 6302 6303 6304 |
# File 'lib/prism/node.rb', line 6296 def initialize(source, node_id, location, flags, else_keyword_loc, statements, end_keyword_loc) @source = source @node_id = node_id @location = location @flags = flags @else_keyword_loc = else_keyword_loc @statements = statements @end_keyword_loc = end_keyword_loc end |
Instance Attribute Details
#statements ⇒ Object (readonly)
attr_reader statements: StatementsNode?
6355 6356 6357 |
# File 'lib/prism/node.rb', line 6355 def statements @statements end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
6397 6398 6399 |
# File 'lib/prism/node.rb', line 6397 def self.type :else_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.
6403 6404 6405 6406 6407 6408 |
# File 'lib/prism/node.rb', line 6403 def ===(other) other.is_a?(ElseNode) && (else_keyword_loc.nil? == other.else_keyword_loc.nil?) && (statements === other.statements) && (end_keyword_loc.nil? == other.end_keyword_loc.nil?) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
6307 6308 6309 |
# File 'lib/prism/node.rb', line 6307 def accept(visitor) visitor.visit_else_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
6312 6313 6314 |
# File 'lib/prism/node.rb', line 6312 def child_nodes [statements] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
6324 6325 6326 |
# File 'lib/prism/node.rb', line 6324 def comment_targets [else_keyword_loc, *statements, *end_keyword_loc] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
6317 6318 6319 6320 6321 |
# File 'lib/prism/node.rb', line 6317 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, else_keyword_loc: self.else_keyword_loc, statements: self.statements, end_keyword_loc: self.end_keyword_loc) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?else_keyword_loc: Location, ?statements: StatementsNode?, ?end_keyword_loc: Location?) -> ElseNode
6329 6330 6331 |
# File 'lib/prism/node.rb', line 6329 def copy(node_id: self.node_id, location: self.location, flags: self.flags, else_keyword_loc: self.else_keyword_loc, statements: self.statements, end_keyword_loc: self.end_keyword_loc) ElseNode.new(source, node_id, location, flags, else_keyword_loc, statements, end_keyword_loc) end |
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, else_keyword_loc: Location, statements: StatementsNode?, end_keyword_loc: Location? }
6337 6338 6339 |
# File 'lib/prism/node.rb', line 6337 def deconstruct_keys(keys) { node_id: node_id, location: location, else_keyword_loc: else_keyword_loc, statements: statements, end_keyword_loc: end_keyword_loc } end |
#else_keyword ⇒ Object
def else_keyword: () -> String
6377 6378 6379 |
# File 'lib/prism/node.rb', line 6377 def else_keyword else_keyword_loc.slice end |
#else_keyword_loc ⇒ Object
attr_reader else_keyword_loc: Location
6342 6343 6344 6345 6346 |
# File 'lib/prism/node.rb', line 6342 def else_keyword_loc location = @else_keyword_loc return location if location.is_a?(Location) @else_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#end_keyword ⇒ Object
def end_keyword: () -> String?
6382 6383 6384 |
# File 'lib/prism/node.rb', line 6382 def end_keyword end_keyword_loc&.slice end |
#end_keyword_loc ⇒ Object
attr_reader end_keyword_loc: Location?
6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 |
# File 'lib/prism/node.rb', line 6358 def end_keyword_loc location = @end_keyword_loc case location when nil nil when Location location else @end_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |
#inspect ⇒ Object
def inspect -> String
6387 6388 6389 |
# File 'lib/prism/node.rb', line 6387 def inspect InspectVisitor.compose(self) end |
#save_else_keyword_loc(repository) ⇒ Object
Save the else_keyword_loc location using the given saved source so that it can be retrieved later.
6350 6351 6352 |
# File 'lib/prism/node.rb', line 6350 def save_else_keyword_loc(repository) repository.enter(node_id, :else_keyword_loc) 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.
6372 6373 6374 |
# File 'lib/prism/node.rb', line 6372 def save_end_keyword_loc(repository) repository.enter(node_id, :end_keyword_loc) unless @end_keyword_loc.nil? end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
6392 6393 6394 |
# File 'lib/prism/node.rb', line 6392 def type :else_node end |