class Prism::CaseMatchNode
Represents the use of a case statement for pattern matching.
case true in false end ^^^^^^^^^
Public Class Methods
Source
# File lib/prism/node.rb, line 4675 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 4779 def conditions @conditions end
Represents the conditions of the case match.
case true; in false; end
^^^^^^^^
Source
# File lib/prism/node_ext.rb, line 476 def consequent deprecated("else_clause") else_clause end
Returns the else clause of the case match node. This method is deprecated in favor of else_clause.
Source
# File lib/prism/node.rb, line 4790 def else_clause @else_clause end
Represents the else clause of the case match.
case true; in false; else; end
^^^^
Source
# File lib/prism/node.rb, line 4768 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
Source
# File lib/prism/node.rb, line 4802 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 ^^^^
Source
# File lib/prism/node.rb, line 4823 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
Public Class Methods
Public Instance Methods
Source
# File lib/prism/node.rb, line 4699 def accept(visitor) visitor.visit_case_match_node(self) end
See Node.accept.
Source
# File lib/prism/node.rb, line 4704 def child_nodes [predicate, *conditions, else_clause] end
See Node.child_nodes.
Source
# File lib/prism/node.rb, line 4727 def comment_targets [*predicate, *conditions, *else_clause, case_keyword_loc, end_keyword_loc] #: Array[Prism::node | Location] end
See Node.comment_targets.
Source
# File lib/prism/node.rb, line 4718 def compact_child_nodes compact = [] #: Array[Prism::node] compact << predicate if predicate compact.concat(conditions) compact << else_clause if else_clause compact end
Source
# File lib/prism/node.rb, line 4735 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.
Source
# File lib/prism/node.rb, line 4709 def each_child_node return to_enum(:each_child_node) unless block_given? yield predicate if predicate conditions.each { |node| yield node } yield else_clause if else_clause end
See Node.each_child_node.
Repository
Public Instance Methods
Source
# File lib/prism/node.rb, line 4811 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.
Source
# File lib/prism/node.rb, line 4832 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 4842 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 4850 def end_keyword end_keyword_loc.slice end
Slice the location of end_keyword_loc from the source.