class Prism::CaseMatchNode - Documentation for Ruby 4.1
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
    ^^^^^^^^^

### 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 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

conditions → Array[InNode]
Source

    # File lib/prism/node.rb, line 5904
    def conditions
      @conditions
    end

Represents the conditions of the case match.

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

else_clause → ElseNode | nil
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
                         ^^^^^^^^^

predicate → Node | nil
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

case_keyword_loc → 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
    ^^^^

end_keyword_loc → 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

type ()
Source

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

See `Node.type`.

### Public Instance Methods

accept (visitor)
Source

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

See `Node.accept`.

child_nodes ()
Source

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

See `Node.child_nodes`.

Also aliased as: deconstruct
comment_targets ()
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`.

compact_child_nodes ()
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

See `Node.compact_child_nodes`.

copy(**fields) → 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.

deconstruct ()
Alias for: child_nodes
each_child_node () { |predicate| ... }
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`.

type ()
Source

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

See `Node#type`.

## Repository

Methods related to `Relocation`.

### Public Instance Methods

save_case_keyword_loc (repository)
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.

save_end_keyword_loc (repository)
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

case_keyword → String
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.

end_keyword → String
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.