class Prism::CaseMatchNode
Represents the use of a case statement for pattern matching.
case true in false end ^^^^^^^^^
Attributes
attr_reader conditions: Array
attr_reader else_clause
: ElseNode
?
attr_reader predicate: Prism::node?
Public Class Methods
Initialize a new CaseMatchNode
node.
# File lib/prism/node.rb, line 3005 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
Return a symbol representation of this node type. See ‘Node::type`.
# File lib/prism/node.rb, line 3098 def self.type :case_match_node end
Public Instance Methods
Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.
# File lib/prism/node.rb, line 3104 def ===(other) other.is_a?(CaseMatchNode) && (predicate === other.predicate) && (conditions.length == other.conditions.length) && conditions.zip(other.conditions).all? { |left, right| left === right } && (else_clause === other.else_clause) && (case_keyword_loc.nil? == other.case_keyword_loc.nil?) && (end_keyword_loc.nil? == other.end_keyword_loc.nil?) end
def accept: (Visitor
visitor) -> void
# File lib/prism/node.rb, line 3018 def accept(visitor) visitor.visit_case_match_node(self) end
def case_keyword
: () -> String
# File lib/prism/node.rb, line 3078 def case_keyword case_keyword_loc.slice end
attr_reader case_keyword_loc
: Location
# File lib/prism/node.rb, line 3064 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
def child_nodes
: () -> Array[nil | Node]
# File lib/prism/node.rb, line 3023 def child_nodes [predicate, *conditions, else_clause] end
def comment_targets
: () -> Array[Node | Location]
# File lib/prism/node.rb, line 3037 def comment_targets [*predicate, *conditions, *else_clause, case_keyword_loc, end_keyword_loc] #: Array[Prism::node | Location] end
def compact_child_nodes
: () -> Array
# File lib/prism/node.rb, line 3028 def compact_child_nodes compact = [] #: Array[Prism::node] compact << predicate if predicate compact.concat(conditions) compact << else_clause if else_clause compact end
Returns the else clause of the case match node. This method is deprecated in favor of else_clause
.
# File lib/prism/node_ext.rb, line 467 def consequent deprecated("else_clause") else_clause end
def copy: (?node_id: Integer
, ?location: Location
, ?flags: Integer
, ?predicate: Prism::node?, ?conditions: Array, ?else_clause: ElseNode
?, ?case_keyword_loc: Location
, ?end_keyword_loc: Location
) -> CaseMatchNode
# File lib/prism/node.rb, line 3042 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
def deconstruct_keys
: (Array keys) -> { node_id: Integer
, location: Location
, predicate: Prism::node?, conditions: Array, else_clause
: ElseNode
?, case_keyword_loc
: Location
, end_keyword_loc
: Location
}
# File lib/prism/node.rb, line 3050 def deconstruct_keys(keys) { node_id: node_id, location: location, predicate: predicate, conditions: conditions, else_clause: else_clause, case_keyword_loc: case_keyword_loc, end_keyword_loc: end_keyword_loc } end
def end_keyword
: () -> String
# File lib/prism/node.rb, line 3083 def end_keyword end_keyword_loc.slice end
attr_reader end_keyword_loc
: Location
# File lib/prism/node.rb, line 3071 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
def inspect -> String
# File lib/prism/node.rb, line 3088 def inspect InspectVisitor.compose(self) end
Return a symbol representation of this node type. See ‘Node#type`.
# File lib/prism/node.rb, line 3093 def type :case_match_node end