class Prism::CaseNode
Represents the use of a case statement.
case true when false end ^^^^^^^^^^
Public Class Methods
Source
# File lib/prism/node.rb, line 6023 def initialize(source, node_id, location, flags, predicate, conditions, else_clause, case_keyword_loc, end_keyword_loc) @source = source @node_id = node_id @location = location @flags = flags @predicate = predicate @conditions = conditions @else_clause = else_clause @case_keyword_loc = case_keyword_loc @end_keyword_loc = end_keyword_loc end
Initialize a new CaseNode node.
Public Instance Methods
Source
# File lib/prism/node.rb, line 6150 def conditions @conditions end
Represents the conditions of the case statement.
case true; when false; end
^^^^^^^^^^
Source
# File lib/prism/node_ext.rb, line 612 def consequent deprecated("else_clause") else_clause end
Returns the else clause of the case node. This method is deprecated in favor of else_clause.
Source
# File lib/prism/node.rb, line 6163 def else_clause @else_clause end
Represents the else clause of the case statement.
case true; when false; else; end
^^^^^^^^^
Source
# File lib/prism/node.rb, line 6137 def predicate @predicate end
Represents the predicate of the case statement. This can be either nil or any non-void expressions.
case true; when false; end
^^^^
Locations
Public Instance Methods
Source
# File lib/prism/node.rb, line 6177 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
Represents the Location of the case keyword.
case true; when false; end ^^^^
Source
# File lib/prism/node.rb, line 6202 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
Represents the Location of the end keyword.
case true; when false; end
^^^
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
Source
# File lib/prism/node.rb, line 6049 def accept(visitor) visitor.visit_case_node(self) end
See Node.accept.
Source
# File lib/prism/node.rb, line 6056 def child_nodes [predicate, *conditions, else_clause] end
See Node.child_nodes.
Source
# File lib/prism/node.rb, line 6086 def comment_targets [*predicate, *conditions, *else_clause, case_keyword_loc, end_keyword_loc] #: Array[Prism::node | Location] end
See Node.comment_targets.
Source
# File lib/prism/node.rb, line 6075 def compact_child_nodes compact = [] #: Array[Prism::node] if (predicate = self.predicate); compact << predicate; end compact.concat(conditions) if (else_clause = self.else_clause); compact << else_clause; end compact end
Source
# File lib/prism/node.rb, line 6096 def copy(node_id: self.node_id, location: self.location, flags: self.flags, predicate: self.predicate, conditions: self.conditions, else_clause: self.else_clause, case_keyword_loc: self.case_keyword_loc, end_keyword_loc: self.end_keyword_loc) CaseNode.new(source, node_id, location, flags, predicate, conditions, else_clause, case_keyword_loc, end_keyword_loc) end
Creates a copy of self with the given fields, using self as the template.
Source
# File lib/prism/node.rb, line 6064 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? if (predicate = self.predicate); yield predicate; end conditions.each { |node| yield node } if (else_clause = self.else_clause); yield else_clause; end end
See Node.each_child_node.
Repository
Methods related to Relocation.
Public Instance Methods
Source
# File lib/prism/node.rb, line 6188 def save_case_keyword_loc(repository) repository.enter(node_id, :case_keyword_loc) end
Save the case_keyword_loc location using the given saved source so that it can be retrieved later.
Source
# File lib/prism/node.rb, line 6213 def save_end_keyword_loc(repository) repository.enter(node_id, :end_keyword_loc) end
Save the end_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 6225 def case_keyword case_keyword_loc.slice end
Slice the location of case_keyword_loc from the source.
Source
# File lib/prism/node.rb, line 6235 def end_keyword end_keyword_loc.slice end
Slice the location of end_keyword_loc from the source.