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 4875 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 4979 def conditions @conditions end
Represents the conditions of the case statement.
case true; when false; end
^^^^^^^^^^
Source
# File lib/prism/node_ext.rb, line 487 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 4990 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 4968 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 5002 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 5023 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
Public Class Methods
Public Instance Methods
Source
# File lib/prism/node.rb, line 4899 def accept(visitor) visitor.visit_case_node(self) end
See Node.accept.
Source
# File lib/prism/node.rb, line 4904 def child_nodes [predicate, *conditions, else_clause] end
See Node.child_nodes.
Source
# File lib/prism/node.rb, line 4927 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 4918 def compact_child_nodes compact = [] #: Array[Prism::node] compact << predicate if predicate compact.concat(conditions) compact << else_clause if else_clause compact end
Source
# File lib/prism/node.rb, line 4935 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 4909 def each_child_node return to_enum(:each_child_node) unless block_given? yield predicate if predicate conditions.each { |node| yield node } yield else_clause if else_clause end
See Node.each_child_node.
Repository
Public Instance Methods
Source
# File lib/prism/node.rb, line 5011 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 5032 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 5042 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 5050 def end_keyword end_keyword_loc.slice end
Slice the location of end_keyword_loc from the source.