Class: Prism::CaseNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::CaseNode
- Defined in:
- lib/prism/node.rb,
lib/prism/node_ext.rb,
ext/prism/api_node.c
Overview
Represents the use of a case statement.
case true
when false
end
^^^^^^^^^^
Instance Attribute Summary collapse
-
#conditions ⇒ Object
readonly
attr_reader conditions: Array.
-
#else_clause ⇒ Object
readonly
attr_reader else_clause: ElseNode?.
-
#predicate ⇒ Object
readonly
attr_reader predicate: Prism::node?.
Class Method Summary collapse
-
.type ⇒ Object
Return a symbol representation of this node type.
Instance Method Summary collapse
-
#===(other) ⇒ Object
Implements case-equality for the node.
-
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void.
-
#case_keyword ⇒ Object
def case_keyword: () -> String.
-
#case_keyword_loc ⇒ Object
attr_reader case_keyword_loc: Location.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#consequent ⇒ Object
Returns the else clause of the case node.
-
#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) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?predicate: Prism::node?, ?conditions: Array, ?else_clause: ElseNode?, ?case_keyword_loc: Location, ?end_keyword_loc: Location) -> CaseNode.
- #deconstruct_keys(keys) ⇒ Object
-
#end_keyword ⇒ Object
def end_keyword: () -> String.
-
#end_keyword_loc ⇒ Object
attr_reader end_keyword_loc: Location.
-
#initialize(source, node_id, location, flags, predicate, conditions, else_clause, case_keyword_loc, end_keyword_loc) ⇒ CaseNode
constructor
Initialize a new CaseNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(source, node_id, location, flags, predicate, conditions, else_clause, case_keyword_loc, end_keyword_loc) ⇒ CaseNode
Initialize a new CaseNode node.
3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 |
# File 'lib/prism/node.rb', line 3086 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 |
Instance Attribute Details
#conditions ⇒ Object (readonly)
attr_reader conditions: Array
3139 3140 3141 |
# File 'lib/prism/node.rb', line 3139 def conditions @conditions end |
#else_clause ⇒ Object (readonly)
attr_reader else_clause: ElseNode?
3142 3143 3144 |
# File 'lib/prism/node.rb', line 3142 def else_clause @else_clause end |
#predicate ⇒ Object (readonly)
attr_reader predicate: Prism::node?
3136 3137 3138 |
# File 'lib/prism/node.rb', line 3136 def predicate @predicate end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
3179 3180 3181 |
# File 'lib/prism/node.rb', line 3179 def self.type :case_node end |
Instance Method Details
#===(other) ⇒ Object
Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.
3185 3186 3187 3188 3189 3190 3191 3192 3193 |
# File 'lib/prism/node.rb', line 3185 def ===(other) other.is_a?(CaseNode) && (predicate === other.predicate) && (conditions.length == other.conditions.length) && conditions.zip(other.conditions).all? { |left, right| left === right } && (else_clause === other.else_clause) && (case_keyword_loc.nil? == other.case_keyword_loc.nil?) && (end_keyword_loc.nil? == other.end_keyword_loc.nil?) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
3099 3100 3101 |
# File 'lib/prism/node.rb', line 3099 def accept(visitor) visitor.visit_case_node(self) end |
#case_keyword ⇒ Object
def case_keyword: () -> String
3159 3160 3161 |
# File 'lib/prism/node.rb', line 3159 def case_keyword case_keyword_loc.slice end |
#case_keyword_loc ⇒ Object
attr_reader case_keyword_loc: Location
3145 3146 3147 3148 3149 |
# File 'lib/prism/node.rb', line 3145 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 |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
3104 3105 3106 |
# File 'lib/prism/node.rb', line 3104 def child_nodes [predicate, *conditions, else_clause] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
3118 3119 3120 |
# File 'lib/prism/node.rb', line 3118 def comment_targets [*predicate, *conditions, *else_clause, case_keyword_loc, end_keyword_loc] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
3109 3110 3111 3112 3113 3114 3115 |
# File 'lib/prism/node.rb', line 3109 def compact_child_nodes compact = [] #: Array[Prism::node] compact << predicate if predicate compact.concat(conditions) compact << else_clause if else_clause compact end |
#consequent ⇒ Object
Returns the else clause of the case node. This method is deprecated in favor of #else_clause.
476 477 478 479 |
# File 'lib/prism/node_ext.rb', line 476 def consequent deprecated("else_clause") else_clause end |
#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) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?predicate: Prism::node?, ?conditions: Array, ?else_clause: ElseNode?, ?case_keyword_loc: Location, ?end_keyword_loc: Location) -> CaseNode
3123 3124 3125 |
# File 'lib/prism/node.rb', line 3123 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 |
#deconstruct_keys(keys) ⇒ Object
3131 3132 3133 |
# File 'lib/prism/node.rb', line 3131 def deconstruct_keys(keys) { node_id: node_id, location: location, predicate: predicate, conditions: conditions, else_clause: else_clause, case_keyword_loc: case_keyword_loc, end_keyword_loc: end_keyword_loc } end |
#end_keyword ⇒ Object
def end_keyword: () -> String
3164 3165 3166 |
# File 'lib/prism/node.rb', line 3164 def end_keyword end_keyword_loc.slice end |
#end_keyword_loc ⇒ Object
attr_reader end_keyword_loc: Location
3152 3153 3154 3155 3156 |
# File 'lib/prism/node.rb', line 3152 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 |
#inspect ⇒ Object
def inspect -> String
3169 3170 3171 |
# File 'lib/prism/node.rb', line 3169 def inspect InspectVisitor.compose(self) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
3174 3175 3176 |
# File 'lib/prism/node.rb', line 3174 def type :case_node end |