123456789_123456789_123456789_123456789_123456789_

Class: Prism::BeginNode

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 a begin statement.

begin
  foo
end
^^^^^

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(source, node_id, location, flags, begin_keyword_loc, statements, rescue_clause, else_clause, ensure_clause, end_keyword_loc) ⇒ BeginNode

Initialize a new BeginNode node.

[ GitHub ]

  
# File 'lib/prism/node.rb', line 1255

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

Class Method Details

.type

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 1361

def self.type
  :begin_node
end

Instance Attribute Details

#else_clause (readonly)

attr_reader else_clause: ElseNode?

[ GitHub ]

  
# File 'lib/prism/node.rb', line 1324

attr_reader :else_clause

#ensure_clause (readonly)

attr_reader ensure_clause: EnsureNode?

[ GitHub ]

  
# File 'lib/prism/node.rb', line 1326

attr_reader :ensure_clause

#rescue_clause (readonly)

attr_reader rescue_clause: RescueNode?

[ GitHub ]

  
# File 'lib/prism/node.rb', line 1322

attr_reader :rescue_clause

#statements (readonly)

attr_reader statements: StatementsNode?

[ GitHub ]

  
# File 'lib/prism/node.rb', line 1320

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.

[ GitHub ]

  
# File 'lib/prism/node.rb', line 1367

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)

def accept: (Visitor visitor) -> void

[ GitHub ]

  
# File 'lib/prism/node.rb', line 1269

def accept(visitor)
  visitor.visit_begin_node(self)
end

#begin_keyword

def begin_keyword: () -> String?

[ GitHub ]

  
# File 'lib/prism/node.rb', line 1341

def begin_keyword
  begin_keyword_loc&.slice
end

#begin_keyword_loc

attr_reader begin_keyword_loc: Location?

[ GitHub ]

  
# File 'lib/prism/node.rb', line 1307

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 Also known as: #deconstruct

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 1274

def child_nodes
  [statements, rescue_clause, else_clause, ensure_clause]
end

#comment_targets

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 1289

def comment_targets
  [*begin_keyword_loc, *statements, *rescue_clause, *else_clause, *ensure_clause, *end_keyword_loc] #: Array[Prism::node | Location]
end

#compact_child_nodes

def compact_child_nodes: () -> Array

[ GitHub ]

  
# File 'lib/prism/node.rb', line 1279

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)

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 1294

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

Alias for #child_nodes.

[ GitHub ]

  
# File 'lib/prism/node.rb', line 1299

alias deconstruct child_nodes

#deconstruct_keys(keys)

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? }

[ GitHub ]

  
# File 'lib/prism/node.rb', line 1302

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

def end_keyword: () -> String?

[ GitHub ]

  
# File 'lib/prism/node.rb', line 1346

def end_keyword
  end_keyword_loc&.slice
end

#end_keyword_loc

attr_reader end_keyword_loc: Location?

[ GitHub ]

  
# File 'lib/prism/node.rb', line 1328

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

def inspect -> String

[ GitHub ]

  
# File 'lib/prism/node.rb', line 1351

def inspect
  InspectVisitor.compose(self)
end

#newline_flag!(lines)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/prism/parse_result/newlines.rb', line 80

def newline_flag!(lines) # :nodoc:
  # Never mark BeginNode with a newline flag, mark children instead.
end

#type

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 1356

def type
  :begin_node
end