class Prism::BeginNode
Represents a begin statement.
begin foo end ^^^^^
Public Class Methods
Source
# File lib/prism/node.rb, line 1920 def initialize(source, node_id, location, flags, begin_keyword_loc, statements, rescue_clause, else_clause, ensure_clause, end_keyword_loc) @source = source @node_id = node_id @location = location @flags = flags @begin_keyword_loc = begin_keyword_loc @statements = statements @rescue_clause = rescue_clause @else_clause = else_clause @ensure_clause = ensure_clause @end_keyword_loc = end_keyword_loc end
Initialize a new BeginNode node.
Public Instance Methods
Source
# File lib/prism/node.rb, line 2064 def else_clause @else_clause end
Represents the else clause within the begin block.
begin x; rescue y; else z; end
^^^^^^
Source
# File lib/prism/node.rb, line 2075 def ensure_clause @ensure_clause end
Represents the ensure clause within the begin block.
begin x; ensure y; end
^^^^^^^^
Source
# File lib/prism/node.rb, line 2053 def rescue_clause @rescue_clause end
Represents the rescue clause within the begin block.
begin x; rescue y; end
^^^^^^^^
Source
# File lib/prism/node.rb, line 2042 def statements @statements end
Represents the statements within the begin block.
begin x end
^
Locations
Public Instance Methods
Source
# File lib/prism/node.rb, line 2017 def begin_keyword_loc location = @begin_keyword_loc case location when nil nil when Location location else @begin_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end
Represents the Location of the begin keyword.
begin x end ^^^^^
Source
# File lib/prism/node.rb, line 2087 def end_keyword_loc location = @end_keyword_loc case location when nil nil when Location location else @end_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end
Represents the Location of the end keyword.
begin x end
^^^
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
Source
# File lib/prism/node.rb, line 1945 def accept(visitor) visitor.visit_begin_node(self) end
See Node.accept.
Source
# File lib/prism/node.rb, line 1950 def child_nodes [statements, rescue_clause, else_clause, ensure_clause] end
See Node.child_nodes.
Source
# File lib/prism/node.rb, line 1975 def comment_targets [*begin_keyword_loc, *statements, *rescue_clause, *else_clause, *ensure_clause, *end_keyword_loc] #: Array[Prism::node | Location] end
See Node.comment_targets.
Source
# File lib/prism/node.rb, line 1965 def compact_child_nodes compact = [] #: Array[Prism::node] compact << statements if statements compact << rescue_clause if rescue_clause compact << else_clause if else_clause compact << ensure_clause if ensure_clause compact end
Source
# File lib/prism/node.rb, line 1983 def copy(node_id: self.node_id, location: self.location, flags: self.flags, begin_keyword_loc: self.begin_keyword_loc, statements: self.statements, rescue_clause: self.rescue_clause, else_clause: self.else_clause, ensure_clause: self.ensure_clause, end_keyword_loc: self.end_keyword_loc) BeginNode.new(source, node_id, location, flags, begin_keyword_loc, statements, rescue_clause, else_clause, ensure_clause, end_keyword_loc) end
Creates a copy of self with the given fields, using self as the template.
Source
# File lib/prism/node.rb, line 1955 def each_child_node return to_enum(:each_child_node) unless block_given? yield statements if statements yield rescue_clause if rescue_clause yield else_clause if else_clause yield ensure_clause if ensure_clause end
See Node.each_child_node.
Repository
Methods related to Relocation.
Public Instance Methods
Source
# File lib/prism/node.rb, line 2032 def save_begin_keyword_loc(repository) repository.enter(node_id, :begin_keyword_loc) unless @begin_keyword_loc.nil? end
Save the begin_keyword_loc location using the given saved source so that it can be retrieved later.
Source
# File lib/prism/node.rb, line 2102 def save_end_keyword_loc(repository) repository.enter(node_id, :end_keyword_loc) unless @end_keyword_loc.nil? end
Save the end_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 2111 def begin_keyword begin_keyword_loc&.slice end
Slice the location of begin_keyword_loc from the source.
Source
# File lib/prism/node.rb, line 2119 def end_keyword end_keyword_loc&.slice end
Slice the location of end_keyword_loc from the source.