Class: Prism::WhileNode
| 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/parse_result/newlines.rb |
Overview
Represents the use of the while keyword, either in the block form or the modifier form.
while foo
^^^^^^^^^^^^^
while foo do end
^^^^^^^^^^^^^^^^^^^^
Class Method Summary
-
.new(source, node_id, location, flags, keyword_loc, closing_loc, predicate, statements) ⇒ WhileNode
constructor
Initialize a new
WhileNodenode. -
.type
Return a symbol representation of this node type.
Instance Attribute Summary
-
#begin_modifier? ⇒ Boolean
readonly
def begin_modifier?: () -> bool.
-
#predicate
readonly
attr_reader predicate:
Prism.node -
#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].
-
#closing
def closing: () -> String?
-
#closing_loc
attr_reader closing_loc: Location?
-
#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, keyword_loc: self.keyword_loc, closing_loc: self.closing_loc, predicate: self.predicate, statements: self.statements)
-
#deconstruct
Alias for #child_nodes.
- #deconstruct_keys(keys)
-
#inspect
def inspect -> String.
-
#keyword
def keyword: () -> String.
-
#keyword_loc
attr_reader keyword_loc:
Location. -
#type
Return a symbol representation of this node type.
- #newline_flag!(lines) Internal use only
Constructor Details
.new(source, node_id, location, flags, keyword_loc, closing_loc, predicate, statements) ⇒ WhileNode
Initialize a new WhileNode node.
# File 'lib/prism/node.rb', line 16000
def initialize(source, node_id, location, flags, keyword_loc, closing_loc, predicate, statements) @source = source @node_id = node_id @location = location @flags = flags @keyword_loc = keyword_loc @closing_loc = closing_loc @predicate = predicate @statements = statements end
Class Method Details
.type
Return a symbol representation of this node type. See Node::type.
# File 'lib/prism/node.rb', line 16097
def self.type :while_node end
Instance Attribute Details
#begin_modifier? ⇒ Boolean (readonly)
def begin_modifier?: () -> bool
# File 'lib/prism/node.rb', line 16048
def begin_modifier? flags.anybits?(LoopFlags::BEGIN_MODIFIER) end
#predicate (readonly)
attr_reader predicate: Prism.node
# File 'lib/prism/node.rb', line 16073
attr_reader :predicate
#statements (readonly)
attr_reader statements: StatementsNode?
# File 'lib/prism/node.rb', line 16075
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 16103
def ===(other) other.is_a?(WhileNode) && (flags === other.flags) && (keyword_loc.nil? == other.keyword_loc.nil?) && (closing_loc.nil? == other.closing_loc.nil?) && (predicate === other.predicate) && (statements === other.statements) end
#accept(visitor)
def accept: (Visitor visitor) -> void
# File 'lib/prism/node.rb', line 16012
def accept(visitor) visitor.visit_while_node(self) end
#child_nodes Also known as: #deconstruct
def child_nodes: () -> Array[nil | Node]
# File 'lib/prism/node.rb', line 16017
def child_nodes [predicate, statements] end
#closing
def closing: () -> String?
# File 'lib/prism/node.rb', line 16082
def closing closing_loc&.slice end
#closing_loc
attr_reader closing_loc: Location?
#comment_targets
def comment_targets: () -> Array[Node | Location]
# File 'lib/prism/node.rb', line 16030
def comment_targets [keyword_loc, *closing_loc, predicate, *statements] #: Array[Prism::node | Location] end
#compact_child_nodes
def compact_child_nodes: () -> Array
# File 'lib/prism/node.rb', line 16022
def compact_child_nodes compact = [] #: Array[Prism::node] compact << predicate compact << statements if statements compact end
#copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, closing_loc: self.closing_loc, predicate: self.predicate, statements: self.statements)
# File 'lib/prism/node.rb', line 16035
def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, closing_loc: self.closing_loc, predicate: self.predicate, statements: self.statements) WhileNode.new(source, node_id, location, flags, keyword_loc, closing_loc, predicate, statements) end
#deconstruct
Alias for #child_nodes.
# File 'lib/prism/node.rb', line 16040
alias deconstruct child_nodes
#deconstruct_keys(keys)
# File 'lib/prism/node.rb', line 16043
def deconstruct_keys(keys) { node_id: node_id, location: location, keyword_loc: keyword_loc, closing_loc: closing_loc, predicate: predicate, statements: statements } end
#inspect
def inspect -> String
# File 'lib/prism/node.rb', line 16087
def inspect InspectVisitor.compose(self) end
#keyword
def keyword: () -> String
# File 'lib/prism/node.rb', line 16077
def keyword keyword_loc.slice end
#keyword_loc
attr_reader keyword_loc: Location
#newline_flag!(lines)
# File 'lib/prism/parse_result/newlines.rb', line 110
def newline_flag!(lines) # :nodoc: predicate.newline_flag!(lines) end
#type
Return a symbol representation of this node type. See Node#type.
# File 'lib/prism/node.rb', line 16092
def type :while_node end