class Prism::WhenNode
Represents the use of the when keyword within a case statement.
case true when true ^^^^^^^^^ end
Public Class Methods
Source
# File lib/prism/node.rb, line 24565 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
Initialize a new WhenNode node.
Public Instance Methods
Source
# File lib/prism/node.rb, line 24670 def conditions @conditions end
Returns the conditions attribute.
Source
# File lib/prism/node.rb, line 24701 def statements @statements end
Returns the statements attribute.
Locations
Public Instance Methods
Source
# File lib/prism/node.rb, line 24653 def keyword_loc location = @keyword_loc return location if location.is_a?(Location) @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end
Returns the Location represented by keyword_loc.
Source
# File lib/prism/node.rb, line 24679 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.
Node Interface
Public Class Methods
Public Instance Methods
Source
# File lib/prism/node.rb, line 24588 def accept(visitor) visitor.visit_when_node(self) end
See Node.accept.
Source
# File lib/prism/node.rb, line 24593 def child_nodes [*conditions, statements] end
See Node.child_nodes.
Also aliased as: deconstruct
Source
# File lib/prism/node.rb, line 24614 def comment_targets [keyword_loc, *conditions, *then_keyword_loc, *statements] #: Array[Prism::node | Location] end
See Node.comment_targets.
Source
# File lib/prism/node.rb, line 24606 def compact_child_nodes compact = [] #: Array[Prism::node] compact.concat(conditions) compact << statements if statements compact end
Source
# File lib/prism/node.rb, line 24622 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
Creates a copy of self with the given fields, using self as the template.
Source
# File lib/prism/node.rb, line 24598 def each_child_node return to_enum(:each_child_node) unless block_given? conditions.each { |node| yield node } yield statements if statements end
See Node.each_child_node.
Repository
Public Instance Methods
Source
# File lib/prism/node.rb, line 24662 def save_keyword_loc(repository) repository.enter(node_id, :keyword_loc) end
Save the keyword_loc location using the given saved source so that it can be retrieved later.
Source
# File lib/prism/node.rb, line 24694 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.
Slicing
Public Instance Methods
Source
# File lib/prism/node.rb, line 24711 def keyword keyword_loc.slice end
Slice the location of keyword_loc from the source.
Source
# File lib/prism/node.rb, line 24719 def then_keyword then_keyword_loc&.slice end
Slice the location of then_keyword_loc from the source.