class Prism::CaseMatchNode
Represents the use of a case statement for pattern matching.
case true in false end ^^^^^^^^^
Public Class Methods
(Source source, Integer node_id, Location location, Integer flags, Prism::node? predicate, Array[InNode] conditions, ElseNode? else_clause, Location case_keyword_loc, Location end_keyword_loc) → void
Source
# File lib/prism/node.rb, line 5777 def initialize(source, node_id, location, flags, predicate, conditions, else_clause, case_keyword_loc, end_keyword_loc) @source = source @node_id = node_id @location = location @flags = flags @predicate = predicate @conditions = conditions @else_clause = else_clause @case_keyword_loc = case_keyword_loc @end_keyword_loc = end_keyword_loc end
Initialize a new CaseMatchNode node.
Public Instance Methods
Source
# File lib/prism/node.rb, line 5904 def conditions @conditions end
Represents the conditions of the case match.
case true; in false; end
^^^^^^^^
Source
# File lib/prism/node.rb, line 5917 def else_clause @else_clause end
Represents the else clause of the case match.
case true; in false; else; end
^^^^^^^^^
() → Prism::node?
Source
# File lib/prism/node.rb, line 5891 def predicate @predicate end
Represents the predicate of the case match. This can be either nil or any non-void expressions.
case true; in false; end
^^^^
Locations
Public Instance Methods
() → Location
Source
# File lib/prism/node.rb, line 5931 def case_keyword_loc location = @case_keyword_loc return location if location.is_a?(Location) @case_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end
Represents the Location of the case keyword.
case true; in false; end ^^^^
() → Location
Source
# File lib/prism/node.rb, line 5956 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
Represents the Location of the end keyword.
case true; in false; end
^^^
Node Interface
These methods are present on all subclasses of Node. Read the node interface docs for more information.
Public Class Methods
Public Instance Methods
(_Visitor visitor) → untyped
Source
# File lib/prism/node.rb, line 5803 def accept(visitor) visitor.visit_case_match_node(self) end
See Node.accept.
() → Array[node?]
Source
# File lib/prism/node.rb, line 5810 def child_nodes [predicate, *conditions, else_clause] end
See Node.child_nodes.
() → Array[node | Location]
Source
# File lib/prism/node.rb, line 5840 def comment_targets [*predicate, *conditions, *else_clause, case_keyword_loc, end_keyword_loc] #: Array[Prism::node | Location] end
See Node.comment_targets.
() → Array[node]
Source
# File lib/prism/node.rb, line 5829 def compact_child_nodes compact = [] #: Array[Prism::node] if (predicate = self.predicate); compact << predicate; end compact.concat(conditions) if (else_clause = self.else_clause); compact << else_clause; end compact end
(?node_id: Integer, ?location: Location, ?flags: Integer, ?predicate: Prism::node?, ?conditions: Array[InNode], ?else_clause: ElseNode?, ?case_keyword_loc: Location, ?end_keyword_loc: Location) → CaseMatchNode
Source
# File lib/prism/node.rb, line 5850 def copy(node_id: self.node_id, location: self.location, flags: self.flags, predicate: self.predicate, conditions: self.conditions, else_clause: self.else_clause, case_keyword_loc: self.case_keyword_loc, end_keyword_loc: self.end_keyword_loc) CaseMatchNode.new(source, node_id, location, flags, predicate, conditions, else_clause, case_keyword_loc, end_keyword_loc) end
Creates a copy of self with the given fields, using self as the template.
() → Enumerator[node, void]
() { (node) → void } → void
Source
# File lib/prism/node.rb, line 5818 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? if (predicate = self.predicate); yield predicate; end conditions.each { |node| yield node } if (else_clause = self.else_clause); yield else_clause; end end
See Node.each_child_node.
Repository
Methods related to Relocation.
Public Instance Methods
(_Repository repository) → Relocation::Entry
Source
# File lib/prism/node.rb, line 5942 def save_case_keyword_loc(repository) repository.enter(node_id, :case_keyword_loc) end
Save the case_keyword_loc location using the given saved source so that it can be retrieved later.
(_Repository repository) → Relocation::Entry
Source
# File lib/prism/node.rb, line 5967 def save_end_keyword_loc(repository) repository.enter(node_id, :end_keyword_loc) 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 5979 def case_keyword case_keyword_loc.slice end
Slice the location of case_keyword_loc from the source.
Source
# File lib/prism/node.rb, line 5989 def end_keyword end_keyword_loc.slice end
Slice the location of end_keyword_loc from the source.