class Prism::ElseNode
Represents an else clause in a case, if, or unless statement.
if a then b else c end
^^^^^^^^^^
Public Class Methods
Source
# File lib/prism/node.rb, line 8515 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
Initialize a new ElseNode node.
Public Instance Methods
Source
# File lib/prism/node.rb, line 8617 def statements @statements end
Returns the statements attribute.
Locations
Public Instance Methods
Source
# File lib/prism/node.rb, line 8600 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
Returns the Location represented by else_keyword_loc.
Source
# File lib/prism/node.rb, line 8626 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
Returns the Location represented by end_keyword_loc.
Node Interface
Public Class Methods
Public Instance Methods
Source
# File lib/prism/node.rb, line 8537 def accept(visitor) visitor.visit_else_node(self) end
See Node.accept.
Source
# File lib/prism/node.rb, line 8542 def child_nodes [statements] end
See Node.child_nodes.
Also aliased as: deconstruct
Source
# File lib/prism/node.rb, line 8561 def comment_targets [else_keyword_loc, *statements, *end_keyword_loc] #: Array[Prism::node | Location] end
See Node.comment_targets.
Source
# File lib/prism/node.rb, line 8554 def compact_child_nodes compact = [] #: Array[Prism::node] compact << statements if statements compact end
Source
# File lib/prism/node.rb, line 8569 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
Creates a copy of self with the given fields, using self as the template.
Source
# File lib/prism/node.rb, line 8547 def each_child_node return to_enum(:each_child_node) unless block_given? yield statements if statements end
See Node.each_child_node.
Repository
Public Instance Methods
Source
# File lib/prism/node.rb, line 8609 def save_else_keyword_loc(repository) repository.enter(node_id, :else_keyword_loc) end
Save the else_keyword_loc location using the given saved source so that it can be retrieved later.
Source
# File lib/prism/node.rb, line 8641 def save_end_keyword_loc(repository) repository.enter(node_id, :end_keyword_loc) unless @end_keyword_loc.nil? end
Save the end_keyword_loc location using the given saved source so that it can be retrieved later.
Slicing
Public Instance Methods
Source
# File lib/prism/node.rb, line 8650 def else_keyword else_keyword_loc.slice end
Slice the location of else_keyword_loc from the source.
Source
# File lib/prism/node.rb, line 8658 def end_keyword end_keyword_loc&.slice end
Slice the location of end_keyword_loc from the source.