class Prism::CaseNode

Represents the use of a case statement.

case true
when false
end
^^^^^^^^^^

Attributes

conditions[R]

attr_reader conditions: Array

consequent[R]

attr_reader consequent: ElseNode?

predicate[R]

attr_reader predicate: Prism::node?

Public Class Methods

new(source, node_id, location, flags, predicate, conditions, consequent, case_keyword_loc, end_keyword_loc) click to toggle source

Initialize a new CaseNode node.

# File lib/prism/node.rb, line 3026
def initialize(source, node_id, location, flags, predicate, conditions, consequent, case_keyword_loc, end_keyword_loc)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @predicate = predicate
  @conditions = conditions
  @consequent = consequent
  @case_keyword_loc = case_keyword_loc
  @end_keyword_loc = end_keyword_loc
end
type() click to toggle source

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

# File lib/prism/node.rb, line 3116
def self.type
  :case_node
end

Public Instance Methods

===(other) click to toggle source

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 3122
def ===(other)
  other.is_a?(CaseNode) &&
    (predicate === other.predicate) &&
    (conditions.length == other.conditions.length) &&
    conditions.zip(other.conditions).all? { |left, right| left === right } &&
    (consequent === other.consequent) &&
    (case_keyword_loc.nil? == other.case_keyword_loc.nil?) &&
    (end_keyword_loc.nil? == other.end_keyword_loc.nil?)
end
accept(visitor) click to toggle source

def accept: (Visitor visitor) -> void

# File lib/prism/node.rb, line 3039
def accept(visitor)
  visitor.visit_case_node(self)
end
case_keyword() click to toggle source

def case_keyword: () -> String

# File lib/prism/node.rb, line 3096
def case_keyword
  case_keyword_loc.slice
end
case_keyword_loc() click to toggle source

attr_reader case_keyword_loc: Location

# File lib/prism/node.rb, line 3082
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
child_nodes() click to toggle source

def child_nodes: () -> Array[nil | Node]

# File lib/prism/node.rb, line 3044
def child_nodes
  [predicate, *conditions, consequent]
end
Also aliased as: deconstruct
comment_targets() click to toggle source

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

# File lib/prism/node.rb, line 3058
def comment_targets
  [*predicate, *conditions, *consequent, case_keyword_loc, end_keyword_loc] #: Array[Prism::node | Location]
end
compact_child_nodes() click to toggle source

def compact_child_nodes: () -> Array

# File lib/prism/node.rb, line 3049
def compact_child_nodes
  compact = [] #: Array[Prism::node]
  compact << predicate if predicate
  compact.concat(conditions)
  compact << consequent if consequent
  compact
end
copy(node_id: self.node_id, location: self.location, flags: self.flags, predicate: self.predicate, conditions: self.conditions, consequent: self.consequent, case_keyword_loc: self.case_keyword_loc, end_keyword_loc: self.end_keyword_loc) click to toggle source

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?predicate: Prism::node?, ?conditions: Array, ?consequent: ElseNode?, ?case_keyword_loc: Location, ?end_keyword_loc: Location) -> CaseNode

# File lib/prism/node.rb, line 3063
def copy(node_id: self.node_id, location: self.location, flags: self.flags, predicate: self.predicate, conditions: self.conditions, consequent: self.consequent, case_keyword_loc: self.case_keyword_loc, end_keyword_loc: self.end_keyword_loc)
  CaseNode.new(source, node_id, location, flags, predicate, conditions, consequent, case_keyword_loc, end_keyword_loc)
end
deconstruct()

def deconstruct: () -> Array[nil | Node]

Alias for: child_nodes
deconstruct_keys(keys) click to toggle source

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, predicate: Prism::node?, conditions: Array, consequent: ElseNode?, case_keyword_loc: Location, end_keyword_loc: Location }

# File lib/prism/node.rb, line 3071
def deconstruct_keys(keys)
  { node_id: node_id, location: location, predicate: predicate, conditions: conditions, consequent: consequent, case_keyword_loc: case_keyword_loc, end_keyword_loc: end_keyword_loc }
end
end_keyword() click to toggle source

def end_keyword: () -> String

# File lib/prism/node.rb, line 3101
def end_keyword
  end_keyword_loc.slice
end
end_keyword_loc() click to toggle source

attr_reader end_keyword_loc: Location

# File lib/prism/node.rb, line 3089
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
inspect() click to toggle source

def inspect -> String

# File lib/prism/node.rb, line 3106
def inspect
  InspectVisitor.compose(self)
end
type() click to toggle source

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

# File lib/prism/node.rb, line 3111
def type
  :case_node
end