123456789_123456789_123456789_123456789_123456789_

Class: Prism::WhenNode

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, PrismNode
Instance Chain:
self, PrismNode
Inherits: PrismNode
Defined in: lib/prism/node.rb,
ext/prism/api_node.c

Overview

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

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

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(source, node_id, location, flags, keyword_loc, conditions, then_keyword_loc, statements) ⇒ WhenNode

Initialize a new WhenNode node.

[ GitHub ]

  
# File 'lib/prism/node.rb', line 15883

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

Class Method Details

.type

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 15975

def self.type
  :when_node
end

Instance Attribute Details

#conditions (readonly)

attr_reader conditions: Array

[ GitHub ]

  
# File 'lib/prism/node.rb', line 15938

attr_reader :conditions

#statements (readonly)

attr_reader statements: StatementsNode?

[ GitHub ]

  
# File 'lib/prism/node.rb', line 15953

attr_reader :statements

Instance Method Details

#===(other)

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 15981

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)

def accept: (Visitor visitor) -> void

[ GitHub ]

  
# File 'lib/prism/node.rb', line 15895

def accept(visitor)
  visitor.visit_when_node(self)
end

#child_nodes Also known as: #deconstruct

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 15900

def child_nodes
  [*conditions, statements]
end

#comment_targets

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 15913

def comment_targets
  [keyword_loc, *conditions, *then_keyword_loc, *statements] #: Array[Prism::node | Location]
end

#compact_child_nodes

def compact_child_nodes: () -> Array

[ GitHub ]

  
# File 'lib/prism/node.rb', line 15905

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)

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 15918

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

Alias for #child_nodes.

[ GitHub ]

  
# File 'lib/prism/node.rb', line 15923

alias deconstruct child_nodes

#deconstruct_keys(keys)

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, keyword_loc: Location, conditions: Array, then_keyword_loc: Location?, statements: StatementsNode? }

[ GitHub ]

  
# File 'lib/prism/node.rb', line 15926

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

def inspect -> String

[ GitHub ]

  
# File 'lib/prism/node.rb', line 15965

def inspect
  InspectVisitor.compose(self)
end

#keyword

def keyword: () -> String

[ GitHub ]

  
# File 'lib/prism/node.rb', line 15955

def keyword
  keyword_loc.slice
end

#keyword_loc

attr_reader keyword_loc: Location

[ GitHub ]

  
# File 'lib/prism/node.rb', line 15931

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

def then_keyword: () -> String?

[ GitHub ]

  
# File 'lib/prism/node.rb', line 15960

def then_keyword
  then_keyword_loc&.slice
end

#then_keyword_loc

attr_reader then_keyword_loc: Location?

[ GitHub ]

  
# File 'lib/prism/node.rb', line 15940

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

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 15970

def type
  :when_node
end