Class: Prism::CaseMatchNode
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
PrismNode
|
|
|
Instance Chain:
self,
PrismNode
|
|
| Inherits: |
PrismNode
|
| Defined in: | lib/prism/node.rb, ext/prism/api_node.c, lib/prism/node_ext.rb |
Overview
Represents the use of a case statement for pattern matching.
case true
in false
end
^^^^^^^^^
Class Method Summary
-
.new(source, node_id, location, flags, predicate, conditions, consequent, case_keyword_loc, end_keyword_loc) ⇒ CaseMatchNode
constructor
Initialize a new
CaseMatchNodenode. -
.type
Return a symbol representation of this node type.
Instance Attribute Summary
-
#conditions
readonly
attr_reader conditions: Array.
-
#consequent
readonly
Returns the else clause of the case match node.
-
#predicate
readonly
attr_reader predicate:
Prism.node?
Instance Method Summary
-
#===(other)
Implements case-equality for the node.
-
#accept(visitor)
def accept: (Visitor visitor) -> void.
-
#case_keyword
def case_keyword: () -> String.
-
#case_keyword_loc
attr_reader case_keyword_loc:
Location. -
#child_nodes
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#comment_targets
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes
def compact_child_nodes: () -> Array.
- #copy(node_id: self.node_id, location: self.location, flags: self.flags, predicate: self.predicate, conditions: self.conditions, consequent: self.consequent, case_keyword_loc: self.case_keyword_loc, end_keyword_loc: self.end_keyword_loc)
-
#deconstruct
Alias for #child_nodes.
- #deconstruct_keys(keys)
-
#end_keyword
def end_keyword: () -> String.
-
#end_keyword_loc
attr_reader end_keyword_loc:
Location. -
#inspect
def inspect -> String.
-
#type
Return a symbol representation of this node type.
Constructor Details
.new(source, node_id, location, flags, predicate, conditions, consequent, case_keyword_loc, end_keyword_loc) ⇒ CaseMatchNode
Initialize a new CaseMatchNode node.
# File 'lib/prism/node.rb', line 2911
def initialize(source, node_id, location, flags, predicate, conditions, consequent, case_keyword_loc, end_keyword_loc) @source = source @node_id = node_id @location = location @flags = flags @predicate = predicate @conditions = conditions @consequent = consequent @case_keyword_loc = case_keyword_loc @end_keyword_loc = end_keyword_loc end
Class Method Details
.type
Return a symbol representation of this node type. See Node::type.
# File 'lib/prism/node.rb', line 3001
def self.type :case_match_node end
Instance Attribute Details
#conditions (readonly)
attr_reader conditions: Array
# File 'lib/prism/node.rb', line 2963
attr_reader :conditions
#consequent (readonly)
Returns the else clause of the case match node. This method is deprecated
in favor of #else_clause.
# File 'lib/prism/node_ext.rb', line 470
attr_reader :consequent
#predicate (readonly)
attr_reader predicate: Prism.node?
# File 'lib/prism/node.rb', line 2961
attr_reader :predicate
Instance Method Details
#===(other)
Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.
# File 'lib/prism/node.rb', line 3007
def ===(other) other.is_a?(CaseMatchNode) && (predicate === other.predicate) && (conditions.length == other.conditions.length) && conditions.zip(other.conditions).all? { |left, right| left === right } && (consequent === other.consequent) && (case_keyword_loc.nil? == other.case_keyword_loc.nil?) && (end_keyword_loc.nil? == other.end_keyword_loc.nil?) end
#accept(visitor)
def accept: (Visitor visitor) -> void
# File 'lib/prism/node.rb', line 2924
def accept(visitor) visitor.visit_case_match_node(self) end
#case_keyword
def case_keyword: () -> String
# File 'lib/prism/node.rb', line 2981
def case_keyword case_keyword_loc.slice end
#case_keyword_loc
attr_reader case_keyword_loc: Location
#child_nodes Also known as: #deconstruct
def child_nodes: () -> Array[nil | Node]
# File 'lib/prism/node.rb', line 2929
def child_nodes [predicate, *conditions, consequent] end
#comment_targets
def comment_targets: () -> Array[Node | Location]
# File 'lib/prism/node.rb', line 2943
def comment_targets [*predicate, *conditions, *consequent, case_keyword_loc, end_keyword_loc] #: Array[Prism::node | Location] end
#compact_child_nodes
def compact_child_nodes: () -> Array
# File 'lib/prism/node.rb', line 2934
def compact_child_nodes compact = [] #: Array[Prism::node] compact << predicate if predicate compact.concat(conditions) compact << consequent if consequent compact end
#copy(node_id: self.node_id, location: self.location, flags: self.flags, predicate: self.predicate, conditions: self.conditions, consequent: self.consequent, case_keyword_loc: self.case_keyword_loc, end_keyword_loc: self.end_keyword_loc)
# File 'lib/prism/node.rb', line 2948
def copy(node_id: self.node_id, location: self.location, flags: self.flags, predicate: self.predicate, conditions: self.conditions, consequent: self.consequent, case_keyword_loc: self.case_keyword_loc, end_keyword_loc: self.end_keyword_loc) CaseMatchNode.new(source, node_id, location, flags, predicate, conditions, consequent, case_keyword_loc, end_keyword_loc) end
#deconstruct
Alias for #child_nodes.
# File 'lib/prism/node.rb', line 2953
alias deconstruct child_nodes
#deconstruct_keys(keys)
# File 'lib/prism/node.rb', line 2956
def deconstruct_keys(keys) { node_id: node_id, location: location, predicate: predicate, conditions: conditions, consequent: consequent, case_keyword_loc: case_keyword_loc, end_keyword_loc: end_keyword_loc } end
#end_keyword
def end_keyword: () -> String
# File 'lib/prism/node.rb', line 2986
def end_keyword end_keyword_loc.slice end
#end_keyword_loc
attr_reader end_keyword_loc: Location
#inspect
def inspect -> String
# File 'lib/prism/node.rb', line 2991
def inspect InspectVisitor.compose(self) end
#type
Return a symbol representation of this node type. See Node#type.
# File 'lib/prism/node.rb', line 2996
def type :case_match_node end