class YARP::CaseNode
Represents the use of a case statement.
case true ^^^^^^^^^ when false end
Attributes
attr_reader case_keyword_loc
: Location
attr_reader conditions: Array
attr_reader consequent: ElseNode
?
attr_reader end_keyword_loc
: Location
attr_reader predicate: Node
?
Public Class Methods
def initialize: (predicate: Node
?, conditions: Array, consequent: ElseNode
?, case_keyword_loc
: Location
, end_keyword_loc
: Location
, location: Location
) -> void
# File lib/yarp/node.rb, line 2168 def initialize(predicate, conditions, consequent, case_keyword_loc, end_keyword_loc, location) @predicate = predicate @conditions = conditions @consequent = consequent @case_keyword_loc = case_keyword_loc @end_keyword_loc = end_keyword_loc @location = location end
Public Instance Methods
def accept: (visitor: Visitor
) -> void
# File lib/yarp/node.rb, line 2178 def accept(visitor) visitor.visit_case_node(self) end
def case_keyword
: () -> String
# File lib/yarp/node.rb, line 2222 def case_keyword case_keyword_loc.slice end
def child_nodes
: () -> Array[nil | Node]
# File lib/yarp/node.rb, line 2183 def child_nodes [predicate, *conditions, consequent] end
def comment_targets
: () -> Array[Node | Location]
# File lib/yarp/node.rb, line 2197 def comment_targets [*predicate, *conditions, *consequent, case_keyword_loc, end_keyword_loc] end
def compact_child_nodes
: () -> Array
# File lib/yarp/node.rb, line 2188 def compact_child_nodes compact = [] compact << predicate if predicate compact.concat(conditions) compact << consequent if consequent compact end
def copy: (**params) -> CaseNode
# File lib/yarp/node.rb, line 2202 def copy(**params) CaseNode.new( params.fetch(:predicate) { predicate }, params.fetch(:conditions) { conditions }, params.fetch(:consequent) { consequent }, params.fetch(:case_keyword_loc) { case_keyword_loc }, params.fetch(:end_keyword_loc) { end_keyword_loc }, params.fetch(:location) { location }, ) end
def deconstruct_keys
: (keys: Array) -> Hash[Symbol, nil | Node
| Array | String
| Token
| Array | Location]
# File lib/yarp/node.rb, line 2217 def deconstruct_keys(keys) { predicate: predicate, conditions: conditions, consequent: consequent, case_keyword_loc: case_keyword_loc, end_keyword_loc: end_keyword_loc, location: location } end
def end_keyword
: () -> String
# File lib/yarp/node.rb, line 2227 def end_keyword end_keyword_loc.slice end
# File lib/yarp/node.rb, line 2231 def inspect(inspector = NodeInspector.new) inspector << inspector.header(self) if (predicate = self.predicate).nil? inspector << "├── predicate: ∅\n" else inspector << "├── predicate:\n" inspector << predicate.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) end inspector << "├── conditions: #{inspector.list("#{inspector.prefix}│ ", conditions)}" if (consequent = self.consequent).nil? inspector << "├── consequent: ∅\n" else inspector << "├── consequent:\n" inspector << consequent.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) end inspector << "├── case_keyword_loc: #{inspector.location(case_keyword_loc)}\n" inspector << "└── end_keyword_loc: #{inspector.location(end_keyword_loc)}\n" inspector.to_str end