Class: Prism::PreExecutionNode

Inherits:
PrismNode
  • Object
show all
Defined in:
lib/prism/node.rb,
sig/generated/prism/node.rbs,
ext/prism/api_node.c

Overview

Represents the use of the BEGIN keyword.

BEGIN { foo }
^^^^^^^^^^^^^

Explore code sample

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, statements, keyword_loc, opening_loc, closing_loc) ⇒ PreExecutionNode

Initialize a new PreExecutionNode node.

: (Source source, Integer node_id, Location location, Integer flags, StatementsNode? statements, Location keyword_loc, Location opening_loc, Location closing_loc) -> void

Parameters:



27223
27224
27225
27226
27227
27228
27229
27230
27231
27232
# File 'lib/prism/node.rb', line 27223

def initialize(source, node_id, location, flags, statements, keyword_loc, opening_loc, closing_loc)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @statements = statements
  @keyword_loc = keyword_loc
  @opening_loc = opening_loc
  @closing_loc = closing_loc
end

Class Method Details

.type ⇒ :pre_execution_node

See Node.type.

: () -> :pre_execution_node

Returns:

  • (:pre_execution_node)


27319
27320
27321
# File 'lib/prism/node.rb', line 27319

def self.type
  :pre_execution_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


27441
27442
27443
27444
27445
27446
27447
# File 'lib/prism/node.rb', line 27441

def ===(other) # :nodoc:
  other.is_a?(PreExecutionNode) &&
    (statements === other.statements) &&
    (keyword_loc.nil? == other.keyword_loc.nil?) &&
    (opening_loc.nil? == other.opening_loc.nil?) &&
    (closing_loc.nil? == other.closing_loc.nil?)
end

#accept(visitor) ⇒ Object

See Node.accept.

: (_Visitor visitor) -> untyped

Parameters:

Returns:

  • (Object)


27248
27249
27250
# File 'lib/prism/node.rb', line 27248

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

#child_nodes ⇒ Array[node?] Also known as: deconstruct

See Node.child_nodes.

: () -> Array

Returns:

  • (Array[node?])


27255
27256
27257
# File 'lib/prism/node.rb', line 27255

def child_nodes
  [statements]
end

#closing ⇒ String

:call-seq:

closing -> String

Slice the location of closing_loc from the source.

: () -> String

Returns:

  • (String)


27434
27435
27436
# File 'lib/prism/node.rb', line 27434

def closing
  closing_loc.slice
end

#closing_loc ⇒ Location

:category: Locations :call-seq:

closing_loc -> Location

Returns the Location represented by closing_loc.

: () -> Location

Returns:



27391
27392
27393
27394
27395
# File 'lib/prism/node.rb', line 27391

def closing_loc
  location = @closing_loc
  return location if location.is_a?(Location)
  @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


27272
27273
27274
27275
27276
# File 'lib/prism/node.rb', line 27272

def compact_child_nodes
  compact = [] #: Array[Prism::node]
  if (statements = self.statements); compact << statements; end
  compact
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, statements: self.statements, keyword_loc: self.keyword_loc, opening_loc: self.opening_loc, closing_loc: self.closing_loc) ⇒ PreExecutionNode

:call-seq:

copy(**fields) -> PreExecutionNode

Creates a copy of self with the given fields, using self as the template.

: (?node_id: Integer, ?location: Location, ?flags: Integer, ?statements: StatementsNode?, ?keyword_loc: Location, ?opening_loc: Location, ?closing_loc: Location) -> PreExecutionNode

Parameters:

  • node_id: (Integer) (defaults to: self.node_id)
  • location: (Location) (defaults to: self.location)
  • flags: (Integer) (defaults to: self.flags)
  • statements: (StatementsNode, nil) (defaults to: self.statements)
  • keyword_loc: (Location) (defaults to: self.keyword_loc)
  • opening_loc: (Location) (defaults to: self.opening_loc)
  • closing_loc: (Location) (defaults to: self.closing_loc)

Returns:



27284
27285
27286
# File 'lib/prism/node.rb', line 27284

def copy(node_id: self.node_id, location: self.location, flags: self.flags, statements: self.statements, keyword_loc: self.keyword_loc, opening_loc: self.opening_loc, closing_loc: self.closing_loc)
  PreExecutionNode.new(source, node_id, location, flags, statements, keyword_loc, opening_loc, closing_loc)
end

#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]

: (Array? keys) -> Hash[Symbol, untyped]

Parameters:

  • keys (Array[Symbol], nil)

Returns:

  • (Hash[Symbol, untyped])


27291
27292
27293
27294
27295
27296
27297
27298
27299
27300
27301
27302
27303
27304
27305
27306
27307
# File 'lib/prism/node.rb', line 27291

def deconstruct_keys(keys) # :nodoc:
  (keys || i[node_id location statements keyword_loc opening_loc closing_loc keyword opening closing]).each_with_object(
    {} #: Hash[Symbol, untyped]
  ) do |key, deconstructed|
    case key
    when :node_id                 then deconstructed[:node_id] = self.node_id
    when :location                then deconstructed[:location] = self.location
    when :statements              then deconstructed[:statements] = self.statements
    when :keyword_loc             then deconstructed[:keyword_loc] = self.keyword_loc
    when :opening_loc             then deconstructed[:opening_loc] = self.opening_loc
    when :closing_loc             then deconstructed[:closing_loc] = self.closing_loc
    when :keyword                 then deconstructed[:keyword] = self.keyword
    when :opening                 then deconstructed[:opening] = self.opening
    when :closing                 then deconstructed[:closing] = self.closing
    end
  end
end

#each_child_node ⇒ Enumerator[node, void] #each_child_node ⇒ void

See Node.each_child_node.

: () -> Enumerator[node, void] : () { (node) -> void } -> void

Overloads:

  • #each_child_node ⇒ Enumerator[node, void]

    Returns:

    • (Enumerator[node, void])
  • #each_child_node ⇒ void

    This method returns an undefined value.

Yields:

Yield Parameters:

  • arg0 (node)

Yield Returns:

  • (void)


27263
27264
27265
27266
27267
# File 'lib/prism/node.rb', line 27263

def each_child_node(&blk)
  return to_enum(:each_child_node) unless block_given?

  if (statements = self.statements); yield statements; end
end

#inspect ⇒ String

: () -> String

Returns:

  • (String)


27324
27325
27326
# File 'lib/prism/node.rb', line 27324

def inspect # :nodoc:
  InspectVisitor.compose(self)
end

#keyword ⇒ String

:call-seq:

keyword -> String

Slice the location of keyword_loc from the source.

: () -> String

Returns:

  • (String)


27414
27415
27416
# File 'lib/prism/node.rb', line 27414

def keyword
  keyword_loc.slice
end

#keyword_loc ⇒ Location

:category: Locations :call-seq:

keyword_loc -> Location

Returns the Location represented by keyword_loc.

: () -> Location

Returns:



27347
27348
27349
27350
27351
# File 'lib/prism/node.rb', line 27347

def keyword_loc
  location = @keyword_loc
  return location if location.is_a?(Location)
  @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#opening ⇒ String

:call-seq:

opening -> String

Slice the location of opening_loc from the source.

: () -> String

Returns:

  • (String)


27424
27425
27426
# File 'lib/prism/node.rb', line 27424

def opening
  opening_loc.slice
end

#opening_loc ⇒ Location

:category: Locations :call-seq:

opening_loc -> Location

Returns the Location represented by opening_loc.

: () -> Location

Returns:



27369
27370
27371
27372
27373
# File 'lib/prism/node.rb', line 27369

def opening_loc
  location = @opening_loc
  return location if location.is_a?(Location)
  @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#save_closing_loc(repository) ⇒ Relocation::Entry

:category: Repository Save the closing_loc location using the given saved source so that it can be retrieved later.

: (_Repository repository) -> Relocation::Entry

Parameters:

Returns:



27402
27403
27404
# File 'lib/prism/node.rb', line 27402

def save_closing_loc(repository)
  repository.enter(node_id, :closing_loc)
end

#save_keyword_loc(repository) ⇒ Relocation::Entry

:category: Repository Save the keyword_loc location using the given saved source so that it can be retrieved later.

: (_Repository repository) -> Relocation::Entry

Parameters:

Returns:



27358
27359
27360
# File 'lib/prism/node.rb', line 27358

def save_keyword_loc(repository)
  repository.enter(node_id, :keyword_loc)
end

#save_opening_loc(repository) ⇒ Relocation::Entry

:category: Repository Save the opening_loc location using the given saved source so that it can be retrieved later.

: (_Repository repository) -> Relocation::Entry

Parameters:

Returns:



27380
27381
27382
# File 'lib/prism/node.rb', line 27380

def save_opening_loc(repository)
  repository.enter(node_id, :opening_loc)
end

#statements ⇒ StatementsNode?

:call-seq:

statements -> StatementsNode | nil

Returns the statements attribute.

: () -> StatementsNode?

Returns:



27336
27337
27338
# File 'lib/prism/node.rb', line 27336

def statements
  @statements
end

#type ⇒ :pre_execution_node

See Node#type.

: () -> :pre_execution_node

Returns:

  • (:pre_execution_node)


27312
27313
27314
# File 'lib/prism/node.rb', line 27312

def type
  :pre_execution_node
end