class Prism::WhileNode
Represents the use of the while keyword, either in the block form or the modifier form.
bar while foo ^^^^^^^^^^^^^ while foo do bar end ^^^^^^^^^^^^^^^^^^^^
Public Class Methods
(Source source, Integer node_id, Location location, Integer flags, Location keyword_loc, Location? do_keyword_loc, Location? closing_loc, Prism::node predicate, StatementsNode? statements) → void
Source
# File lib/prism/node.rb, line 30863 def initialize(source, node_id, location, flags, keyword_loc, do_keyword_loc, closing_loc, predicate, statements) @source = source @node_id = node_id @location = location @flags = flags @keyword_loc = keyword_loc @do_keyword_loc = do_keyword_loc @closing_loc = closing_loc @predicate = predicate @statements = statements end
Initialize a new WhileNode node.
Public Instance Methods
() → Prism::node
Source
# File lib/prism/node.rb, line 31056 def predicate @predicate end
Returns the predicate attribute.
Source
# File lib/prism/node.rb, line 31066 def statements @statements end
Returns the statements attribute.
Flags
Public Instance Methods
() → bool
Source
# File lib/prism/node.rb, line 30970 def begin_modifier? flags.anybits?(LoopFlags::BEGIN_MODIFIER) end
a loop after a begin statement, so the body is executed first before the condition
Locations
Public Instance Methods
() → Location?
Source
# File lib/prism/node.rb, line 31030 def closing_loc location = @closing_loc case location when nil nil when Location location else @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end
Returns the Location represented by closing_loc.
() → Location?
Source
# File lib/prism/node.rb, line 31003 def do_keyword_loc location = @do_keyword_loc case location when nil nil when Location location else @do_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end
Returns the Location represented by do_keyword_loc.
() → Location
Source
# File lib/prism/node.rb, line 30981 def keyword_loc location = @keyword_loc return location if location.is_a?(Location) @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end
Returns the Location represented by keyword_loc.
Node Interface
These methods are present on all subclasses of Node. Read the node interface docs for more information.
Public Class Methods
Public Instance Methods
(_Visitor visitor) → untyped
Source
# File lib/prism/node.rb, line 30889 def accept(visitor) visitor.visit_while_node(self) end
See Node.accept.
() → Array[node?]
Source
# File lib/prism/node.rb, line 30896 def child_nodes [predicate, statements] end
See Node.child_nodes.
() → Array[node | Location]
Source
# File lib/prism/node.rb, line 30924 def comment_targets [keyword_loc, *do_keyword_loc, *closing_loc, predicate, *statements] #: Array[Prism::node | Location] end
See Node.comment_targets.
() → Array[node]
Source
# File lib/prism/node.rb, line 30914 def compact_child_nodes compact = [] #: Array[Prism::node] compact << predicate if (statements = self.statements); compact << statements; end compact end
(?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?do_keyword_loc: Location?, ?closing_loc: Location?, ?predicate: Prism::node, ?statements: StatementsNode?) → WhileNode
Source
# File lib/prism/node.rb, line 30934 def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, do_keyword_loc: self.do_keyword_loc, closing_loc: self.closing_loc, predicate: self.predicate, statements: self.statements) WhileNode.new(source, node_id, location, flags, keyword_loc, do_keyword_loc, closing_loc, predicate, statements) end
Creates a copy of self with the given fields, using self as the template.
() → Enumerator[node, void]
() { (node) → void } → void
Source
# File lib/prism/node.rb, line 30904 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? yield predicate if (statements = self.statements); yield statements; end end
See Node.each_child_node.
Repository
Methods related to Relocation.
Public Instance Methods
(_Repository repository) → Relocation::Entry?
Source
# File lib/prism/node.rb, line 31047 def save_closing_loc(repository) repository.enter(node_id, :closing_loc) unless @closing_loc.nil? end
Save the closing_loc location using the given saved source so that it can be retrieved later.
(_Repository repository) → Relocation::Entry?
Source
# File lib/prism/node.rb, line 31020 def save_do_keyword_loc(repository) repository.enter(node_id, :do_keyword_loc) unless @do_keyword_loc.nil? end
Save the do_keyword_loc location using the given saved source so that it can be retrieved later.
(_Repository repository) → Relocation::Entry
Source
# File lib/prism/node.rb, line 30992 def save_keyword_loc(repository) repository.enter(node_id, :keyword_loc) end
Save the keyword_loc location using the given saved source so that it can be retrieved later.
Slicing
Public Instance Methods
() → String?
Source
# File lib/prism/node.rb, line 31098 def closing closing_loc&.slice end
Slice the location of closing_loc from the source.
Source
# File lib/prism/node.rb, line 31088 def do_keyword do_keyword_loc&.slice end
Slice the location of do_keyword_loc from the source.
() → String
Source
# File lib/prism/node.rb, line 31078 def keyword keyword_loc.slice end
Slice the location of keyword_loc from the source.