class Prism::CaseMatchNode - Documentation for Ruby 4.0
Description: class Prism::CaseMatchNode: Represents the use of a case statement for pattern matching.
Keywords: ruby,class,Prism::CaseMatchNode

🔍

No recent searches

# class Prism::CaseMatchNode

Represents the use of a case statement for pattern matching.

    case true
    in false
    end
    ^^^^^^^^^

### Attributes

conditions [R]

Represents the conditions of the case match.

    case true; in false; end
               ^^^^^^^^

else_clause [R]

Represents the else clause of the case match.

    case true; in false; else; end
                         ^^^^

predicate [R]

Represents the predicate of the case match. This can be either `nil` or any non-void expressions.

    case true; in false; end
    ^^^^

### Public Class Methods

new (source, node_id, location, flags, predicate, conditions, else_clause, case_keyword_loc, end_keyword_loc)
Source

    # File lib/prism/node.rb, line 3754
    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.

type ()
Source

    # File lib/prism/node.rb, line 3883
    def self.type
      :case_match_node
    end

Return a symbol representation of this node type. See `Node::type`.

### Public Instance Methods

=== (other)
Source

    # File lib/prism/node.rb, line 3889
    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

Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.

accept (visitor)
Source

    # File lib/prism/node.rb, line 3767
    def accept(visitor)
      visitor.visit_case_match_node(self)
    end

def accept: (`Visitor` visitor) -> void

case_keyword ()
Source

    # File lib/prism/node.rb, line 3863
    def case_keyword
      case_keyword_loc.slice
    end

def `case_keyword`: () -> `String`

case_keyword_loc ()
Source

    # File lib/prism/node.rb, line 3834
    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
    ^^^^

child_nodes ()
Source

    # File lib/prism/node.rb, line 3772
    def child_nodes
      [predicate, *conditions, else_clause]
    end

def `child_nodes`: () -> Array

Also aliased as: deconstruct
comment_targets ()
Source

    # File lib/prism/node.rb, line 3795
    def comment_targets
      [*predicate, *conditions, *else_clause, case_keyword_loc, end_keyword_loc] #: Array[Prism::node | Location]
    end

def `comment_targets`: () -> Array[Node | Location]

compact_child_nodes ()
Source

    # File lib/prism/node.rb, line 3786
    def compact_child_nodes
      compact = [] #: Array[Prism::node]
      compact << predicate if predicate
      compact.concat(conditions)
      compact << else_clause if else_clause
      compact
    end

def `compact_child_nodes`: () -> Array

consequent ()
Source

    # File lib/prism/node_ext.rb, line 470
    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`.

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)
Source

    # File lib/prism/node.rb, line 3800
    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 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`

deconstruct ()

def deconstruct: () -> Array

Alias for: child_nodes
deconstruct_keys (keys)
Source

    # File lib/prism/node.rb, line 3808
    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 `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` }

each_child_node () { |predicate| ... }
Source

    # File lib/prism/node.rb, line 3777
    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

def `each_child_node`: () { (Prism::node) -> void } -> void | () -> Enumerator

end_keyword ()
Source

    # File lib/prism/node.rb, line 3868
    def end_keyword
      end_keyword_loc.slice
    end

def `end_keyword`: () -> `String`

end_keyword_loc ()
Source

    # File lib/prism/node.rb, line 3850
    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
                         ^^^

inspect ()
Source

    # File lib/prism/node.rb, line 3873
    def inspect
      InspectVisitor.compose(self)
    end

def inspect -> `String`

save_case_keyword_loc (repository)
Source

    # File lib/prism/node.rb, line 3842
    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.

save_end_keyword_loc (repository)
Source

    # File lib/prism/node.rb, line 3858
    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.

type ()
Source

    # File lib/prism/node.rb, line 3878
    def type
      :case_match_node
    end

Return a symbol representation of this node type. See `Node#type`.