class Prism::WhenNode

Represents the use of the ‘when` keyword within a case statement.

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

Attributes

conditions[R]

attr_reader conditions: Array

statements[R]

attr_reader statements: StatementsNode?

Public Class Methods

new(source, node_id, location, flags, keyword_loc, conditions, then_keyword_loc, statements) click to toggle source

Initialize a new WhenNode node.

# File prism/node.rb, line 16194
def initialize(source, node_id, location, flags, keyword_loc, conditions, then_keyword_loc, statements)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @keyword_loc = keyword_loc
  @conditions = conditions
  @then_keyword_loc = then_keyword_loc
  @statements = statements
end
type() click to toggle source

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

# File prism/node.rb, line 16288
def self.type
  :when_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 prism/node.rb, line 16294
def ===(other)
  other.is_a?(WhenNode) &&
    (keyword_loc.nil? == other.keyword_loc.nil?) &&
    (conditions.length == other.conditions.length) &&
    conditions.zip(other.conditions).all? { |left, right| left === right } &&
    (then_keyword_loc.nil? == other.then_keyword_loc.nil?) &&
    (statements === other.statements)
end
accept(visitor) click to toggle source

def accept: (Visitor visitor) -> void

# File prism/node.rb, line 16206
def accept(visitor)
  visitor.visit_when_node(self)
end
child_nodes() click to toggle source

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

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

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

# File prism/node.rb, line 16224
def comment_targets
  [keyword_loc, *conditions, *then_keyword_loc, *statements] #: Array[Prism::node | Location]
end
compact_child_nodes() click to toggle source

def compact_child_nodes: () -> Array

# File prism/node.rb, line 16216
def compact_child_nodes
  compact = [] #: Array[Prism::node]
  compact.concat(conditions)
  compact << statements if statements
  compact
end
copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, conditions: self.conditions, then_keyword_loc: self.then_keyword_loc, statements: self.statements) click to toggle source

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?conditions: Array, ?then_keyword_loc: Location?, ?statements: StatementsNode?) -> WhenNode

# File prism/node.rb, line 16229
def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, conditions: self.conditions, then_keyword_loc: self.then_keyword_loc, statements: self.statements)
  WhenNode.new(source, node_id, location, flags, keyword_loc, conditions, then_keyword_loc, statements)
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, keyword_loc: Location, conditions: Array, then_keyword_loc: Location?, statements: StatementsNode? }

# File prism/node.rb, line 16237
def deconstruct_keys(keys)
  { node_id: node_id, location: location, keyword_loc: keyword_loc, conditions: conditions, then_keyword_loc: then_keyword_loc, statements: statements }
end
inspect() click to toggle source

def inspect -> String

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

def keyword: () -> String

# File prism/node.rb, line 16268
def keyword
  keyword_loc.slice
end
keyword_loc() click to toggle source

attr_reader keyword_loc: Location

# File prism/node.rb, line 16242
def keyword_loc
  location = @keyword_loc
  return location if location.is_a?(Location)
  @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end
then_keyword() click to toggle source

def then_keyword: () -> String?

# File prism/node.rb, line 16273
def then_keyword
  then_keyword_loc&.slice
end
then_keyword_loc() click to toggle source

attr_reader then_keyword_loc: Location?

# File prism/node.rb, line 16252
def then_keyword_loc
  location = @then_keyword_loc
  case location
  when nil
    nil
  when Location
    location
  else
    @then_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
  end
end
type() click to toggle source

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

# File prism/node.rb, line 16283
def type
  :when_node
end