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
# File lib/prism/node.rb, line 24744 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
Source
# File lib/prism/node.rb, line 24902 def predicate @predicate end
Returns the predicate attribute.
Source
# File lib/prism/node.rb, line 24910 def statements @statements end
Returns the statements attribute.
Flags
Public Instance Methods
Source
# File lib/prism/node.rb, line 24830 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
Source
# File lib/prism/node.rb, line 24880 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.
Source
# File lib/prism/node.rb, line 24857 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.
Source
# File lib/prism/node.rb, line 24839 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
Public Class Methods
Public Instance Methods
Source
# File lib/prism/node.rb, line 24768 def accept(visitor) visitor.visit_while_node(self) end
See Node.accept.
Source
# File lib/prism/node.rb, line 24773 def child_nodes [predicate, statements] end
See Node.child_nodes.
Source
# File lib/prism/node.rb, line 24794 def comment_targets [keyword_loc, *do_keyword_loc, *closing_loc, predicate, *statements] #: Array[Prism::node | Location] end
See Node.comment_targets.
Source
# File lib/prism/node.rb, line 24786 def compact_child_nodes compact = [] #: Array[Prism::node] compact << predicate compact << statements if statements compact end
Source
# File lib/prism/node.rb, line 24802 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.
Source
# File lib/prism/node.rb, line 24778 def each_child_node return to_enum(:each_child_node) unless block_given? yield predicate yield statements if statements end
See Node.each_child_node.
Repository
Public Instance Methods
Source
# File lib/prism/node.rb, line 24895 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.
Source
# File lib/prism/node.rb, line 24872 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.
Source
# File lib/prism/node.rb, line 24848 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
Source
# File lib/prism/node.rb, line 24936 def closing closing_loc&.slice end
Slice the location of closing_loc from the source.
Source
# File lib/prism/node.rb, line 24928 def do_keyword do_keyword_loc&.slice end
Slice the location of do_keyword_loc from the source.
Source
# File lib/prism/node.rb, line 24920 def keyword keyword_loc.slice end
Slice the location of keyword_loc from the source.