Class: Prism::ElseNode
| 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 |
Overview
Represents an else clause in a case, if, or unless statement.
if a then b else c end
^^^^^^^^^^
Class Method Summary
-
.new(source, node_id, location, flags, else_keyword_loc, statements, end_keyword_loc) ⇒ ElseNode
constructor
Initialize a new
ElseNodenode. -
.type
Return a symbol representation of this node type.
Instance Attribute Summary
-
#statements
readonly
attr_reader statements: StatementsNode?
Instance Method Summary
-
#===(other)
Implements case-equality for the node.
-
#accept(visitor)
def accept: (Visitor visitor) -> void.
-
#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, else_keyword_loc: self.else_keyword_loc, statements: self.statements, end_keyword_loc: self.end_keyword_loc)
-
#deconstruct
Alias for #child_nodes.
- #deconstruct_keys(keys)
-
#else_keyword
def else_keyword: () -> String.
-
#else_keyword_loc
attr_reader else_keyword_loc:
Location. -
#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, else_keyword_loc, statements, end_keyword_loc) ⇒ ElseNode
Initialize a new ElseNode node.
# File 'lib/prism/node.rb', line 5341
def initialize(source, node_id, location, flags, else_keyword_loc, statements, end_keyword_loc) @source = source @node_id = node_id @location = location @flags = flags @else_keyword_loc = else_keyword_loc @statements = statements @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 5429
def self.type :else_node end
Instance Attribute Details
#statements (readonly)
attr_reader statements: StatementsNode?
# File 'lib/prism/node.rb', line 5394
attr_reader :statements
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 5435
def ===(other) other.is_a?(ElseNode) && (else_keyword_loc.nil? == other.else_keyword_loc.nil?) && (statements === other.statements) && (end_keyword_loc.nil? == other.end_keyword_loc.nil?) end
#accept(visitor)
def accept: (Visitor visitor) -> void
# File 'lib/prism/node.rb', line 5352
def accept(visitor) visitor.visit_else_node(self) end
#child_nodes Also known as: #deconstruct
def child_nodes: () -> Array[nil | Node]
# File 'lib/prism/node.rb', line 5357
def child_nodes [statements] end
#comment_targets
def comment_targets: () -> Array[Node | Location]
# File 'lib/prism/node.rb', line 5369
def comment_targets [else_keyword_loc, *statements, *end_keyword_loc] #: Array[Prism::node | Location] end
#compact_child_nodes
def compact_child_nodes: () -> Array
# File 'lib/prism/node.rb', line 5362
def compact_child_nodes compact = [] #: Array[Prism::node] compact << statements if statements compact end
#copy(node_id: self.node_id, location: self.location, flags: self.flags, else_keyword_loc: self.else_keyword_loc, statements: self.statements, end_keyword_loc: self.end_keyword_loc)
# File 'lib/prism/node.rb', line 5374
def copy(node_id: self.node_id, location: self.location, flags: self.flags, else_keyword_loc: self.else_keyword_loc, statements: self.statements, end_keyword_loc: self.end_keyword_loc) ElseNode.new(source, node_id, location, flags, else_keyword_loc, statements, end_keyword_loc) end
#deconstruct
Alias for #child_nodes.
# File 'lib/prism/node.rb', line 5379
alias deconstruct child_nodes
#deconstruct_keys(keys)
# File 'lib/prism/node.rb', line 5382
def deconstruct_keys(keys) { node_id: node_id, location: location, else_keyword_loc: else_keyword_loc, statements: statements, end_keyword_loc: end_keyword_loc } end
#else_keyword
def else_keyword: () -> String
# File 'lib/prism/node.rb', line 5409
def else_keyword else_keyword_loc.slice end
#else_keyword_loc
attr_reader else_keyword_loc: Location
#end_keyword
def end_keyword: () -> String?
# File 'lib/prism/node.rb', line 5414
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 5419
def inspect InspectVisitor.compose(self) end
#type
Return a symbol representation of this node type. See Node#type.
# File 'lib/prism/node.rb', line 5424
def type :else_node end