class Prism::BeginNode

Represents a begin statement.

begin
  foo
end
^^^^^

Attributes

else_clause[R]

attr_reader else_clause: ElseNode?

ensure_clause[R]

attr_reader ensure_clause: EnsureNode?

rescue_clause[R]

attr_reader rescue_clause: RescueNode?

statements[R]

attr_reader statements: StatementsNode?

Public Class Methods

new(source, node_id, location, flags, begin_keyword_loc, statements, rescue_clause, else_clause, ensure_clause, end_keyword_loc) click to toggle source

Initialize a new BeginNode node.

# File prism/node.rb, line 1315
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
type() click to toggle source

Return a symbol representation of this node type. See ‘Node::type`.

# File prism/node.rb, line 1425
def self.type
  :begin_node
end

Public Instance Methods

===(other) click to toggle source

Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.

# File prism/node.rb, line 1431
def ===(other)
  other.is_a?(BeginNode) &&
    (begin_keyword_loc.nil? == other.begin_keyword_loc.nil?) &&
    (statements === other.statements) &&
    (rescue_clause === other.rescue_clause) &&
    (else_clause === other.else_clause) &&
    (ensure_clause === other.ensure_clause) &&
    (end_keyword_loc.nil? == other.end_keyword_loc.nil?)
end
accept(visitor) click to toggle source

def accept: (Visitor visitor) -> void

# File prism/node.rb, line 1329
def accept(visitor)
  visitor.visit_begin_node(self)
end
begin_keyword() click to toggle source

def begin_keyword: () -> String?

# File prism/node.rb, line 1405
def begin_keyword
  begin_keyword_loc&.slice
end
begin_keyword_loc() click to toggle source

attr_reader begin_keyword_loc: Location?

# File prism/node.rb, line 1367
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
child_nodes() click to toggle source

def child_nodes: () -> Array[nil | Node]

# File prism/node.rb, line 1334
def child_nodes
  [statements, rescue_clause, else_clause, ensure_clause]
end
Also aliased as: deconstruct
comment_targets() click to toggle source

def comment_targets: () -> Array[Node | Location]

# File prism/node.rb, line 1349
def comment_targets
  [*begin_keyword_loc, *statements, *rescue_clause, *else_clause, *ensure_clause, *end_keyword_loc] #: Array[Prism::node | Location]
end
compact_child_nodes() click to toggle source

def compact_child_nodes: () -> Array

# File prism/node.rb, line 1339
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
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) click to toggle source

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?begin_keyword_loc: Location?, ?statements: StatementsNode?, ?rescue_clause: RescueNode?, ?else_clause: ElseNode?, ?ensure_clause: EnsureNode?, ?end_keyword_loc: Location?) -> BeginNode

# File prism/node.rb, line 1354
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
deconstruct()

def deconstruct: () -> Array[nil | Node]

Alias for: child_nodes
deconstruct_keys(keys) click to toggle source

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, begin_keyword_loc: Location?, statements: StatementsNode?, rescue_clause: RescueNode?, else_clause: ElseNode?, ensure_clause: EnsureNode?, end_keyword_loc: Location? }

# File prism/node.rb, line 1362
def deconstruct_keys(keys)
  { node_id: node_id, location: location, 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
end_keyword() click to toggle source

def end_keyword: () -> String?

# File prism/node.rb, line 1410
def end_keyword
  end_keyword_loc&.slice
end
end_keyword_loc() click to toggle source

attr_reader end_keyword_loc: Location?

# File prism/node.rb, line 1392
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
inspect() click to toggle source

def inspect -> String

# File prism/node.rb, line 1415
def inspect
  InspectVisitor.compose(self)
end
type() click to toggle source

Return a symbol representation of this node type. See ‘Node#type`.

# File prism/node.rb, line 1420
def type
  :begin_node
end