class Prism::WhenNode
Represents the use of the when keyword within a case statement.
case true when true ^^^^^^^^^ end
Public Class Methods
(Source source, Integer node_id, Location location, Integer flags, Location when_keyword_loc, Array[Prism::node] conditions, Location? then_keyword_loc, StatementsNode? statements) → void
Source
# File lib/prism/node.rb, line 32349 def initialize(source, node_id, location, flags, when_keyword_loc, conditions, then_keyword_loc, statements) @source = source @node_id = node_id @location = location @flags = flags @when_keyword_loc = when_keyword_loc @conditions = conditions @then_keyword_loc = then_keyword_loc @statements = statements end
Initialize a new WhenNode node.
Public Instance Methods
() → Array[Prism::node]
Source
# File lib/prism/node.rb, line 32492 def conditions @conditions end
Returns the conditions attribute.
Source
# File lib/prism/node.rb, line 32529 def statements @statements end
Returns the statements attribute.
Locations
Public Instance Methods
() → Location?
Source
# File lib/prism/node.rb, line 32503 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
Returns the Location represented by then_keyword_loc.
() → Location
Source
# File lib/prism/node.rb, line 32471 def when_keyword_loc location = @when_keyword_loc return location if location.is_a?(Location) @when_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end
Returns the Location represented by when_keyword_loc.
Node Interface
These methods are present on all subclasses of Node. Read the node interface docs for more information.
Public Class Methods
Public Instance Methods
(_Visitor visitor) → untyped
Source
# File lib/prism/node.rb, line 32374 def accept(visitor) visitor.visit_when_node(self) end
See Node.accept.
() → Array[node?]
Source
# File lib/prism/node.rb, line 32381 def child_nodes [*conditions, statements] end
See Node.child_nodes.
() → Array[node | Location]
Source
# File lib/prism/node.rb, line 32409 def comment_targets [when_keyword_loc, *conditions, *then_keyword_loc, *statements] #: Array[Prism::node | Location] end
See Node.comment_targets.
() → Array[node]
Source
# File lib/prism/node.rb, line 32399 def compact_child_nodes compact = [] #: Array[Prism::node] compact.concat(conditions) if (statements = self.statements); compact << statements; end compact end
(?node_id: Integer, ?location: Location, ?flags: Integer, ?when_keyword_loc: Location, ?conditions: Array[Prism::node], ?then_keyword_loc: Location?, ?statements: StatementsNode?) → WhenNode
Source
# File lib/prism/node.rb, line 32419 def copy(node_id: self.node_id, location: self.location, flags: self.flags, when_keyword_loc: self.when_keyword_loc, conditions: self.conditions, then_keyword_loc: self.then_keyword_loc, statements: self.statements) WhenNode.new(source, node_id, location, flags, when_keyword_loc, conditions, then_keyword_loc, statements) end
Creates a copy of self with the given fields, using self as the template.
() → Enumerator[node, void]
() { (node) → void } → void
Source
# File lib/prism/node.rb, line 32389 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? conditions.each { |node| yield node } if (statements = self.statements); yield statements; end end
See Node.each_child_node.
Repository
Methods related to Relocation.
Public Instance Methods
(_Repository repository) → Relocation::Entry?
Source
# File lib/prism/node.rb, line 32520 def save_then_keyword_loc(repository) repository.enter(node_id, :then_keyword_loc) unless @then_keyword_loc.nil? end
Save the then_keyword_loc location using the given saved source so that it can be retrieved later.
(_Repository repository) → Relocation::Entry
Source
# File lib/prism/node.rb, line 32482 def save_when_keyword_loc(repository) repository.enter(node_id, :when_keyword_loc) end
Save the when_keyword_loc location using the given saved source so that it can be retrieved later.
Slicing
Public Instance Methods
Source
# File lib/prism/node.rb, line 32551 def then_keyword then_keyword_loc&.slice end
Slice the location of then_keyword_loc from the source.
Source
# File lib/prism/node.rb, line 32541 def when_keyword when_keyword_loc.slice end
Slice the location of when_keyword_loc from the source.