Class: Prism::NextNode

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 next keyword.

next 1
^^^^^^

Explore code sample

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, arguments, keyword_loc) ⇒ NextNode

Initialize a new NextNode node.

: (Source source, Integer node_id, Location location, Integer flags, ArgumentsNode? arguments, Location keyword_loc) -> void

Parameters:



24528
24529
24530
24531
24532
24533
24534
24535
# File 'lib/prism/node.rb', line 24528

def initialize(source, node_id, location, flags, arguments, keyword_loc)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @arguments = arguments
  @keyword_loc = keyword_loc
end

Class Method Details

.type ⇒ :next_node

See Node.type.

: () -> :next_node

Returns:

  • (:next_node)


24618
24619
24620
# File 'lib/prism/node.rb', line 24618

def self.type
  :next_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


24676
24677
24678
24679
24680
# File 'lib/prism/node.rb', line 24676

def ===(other) # :nodoc:
  other.is_a?(NextNode) &&
    (arguments === other.arguments) &&
    (keyword_loc.nil? == other.keyword_loc.nil?)
end

#accept(visitor) ⇒ Object

See Node.accept.

: (_Visitor visitor) -> untyped

Parameters:

Returns:

  • (Object)


24551
24552
24553
# File 'lib/prism/node.rb', line 24551

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

#arguments ⇒ ArgumentsNode?

:call-seq:

arguments -> ArgumentsNode | nil

Returns the arguments attribute.

: () -> ArgumentsNode?

Returns:



24635
24636
24637
# File 'lib/prism/node.rb', line 24635

def arguments
  @arguments
end

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

See Node.child_nodes.

: () -> Array

Returns:

  • (Array[node?])


24558
24559
24560
# File 'lib/prism/node.rb', line 24558

def child_nodes
  [arguments]
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


24575
24576
24577
24578
24579
# File 'lib/prism/node.rb', line 24575

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

#copy(node_id: self.node_id, location: self.location, flags: self.flags, arguments: self.arguments, keyword_loc: self.keyword_loc) ⇒ NextNode

:call-seq:

copy(**fields) -> NextNode

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

: (?node_id: Integer, ?location: Location, ?flags: Integer, ?arguments: ArgumentsNode?, ?keyword_loc: Location) -> NextNode

Parameters:

  • node_id: (Integer) (defaults to: self.node_id)
  • location: (Location) (defaults to: self.location)
  • flags: (Integer) (defaults to: self.flags)
  • arguments: (ArgumentsNode, nil) (defaults to: self.arguments)
  • keyword_loc: (Location) (defaults to: self.keyword_loc)

Returns:



24587
24588
24589
# File 'lib/prism/node.rb', line 24587

def copy(node_id: self.node_id, location: self.location, flags: self.flags, arguments: self.arguments, keyword_loc: self.keyword_loc)
  NextNode.new(source, node_id, location, flags, arguments, keyword_loc)
end

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

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

Parameters:

  • keys (Array[Symbol], nil)

Returns:

  • (Hash[Symbol, untyped])


24594
24595
24596
24597
24598
24599
24600
24601
24602
24603
24604
24605
24606
# File 'lib/prism/node.rb', line 24594

def deconstruct_keys(keys) # :nodoc:
  (keys || %i[node_id location arguments keyword_loc keyword]).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 :arguments               then deconstructed[:arguments] = self.arguments
    when :keyword_loc             then deconstructed[:keyword_loc] = self.keyword_loc
    when :keyword                 then deconstructed[:keyword] = self.keyword
    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)


24566
24567
24568
24569
24570
# File 'lib/prism/node.rb', line 24566

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

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

#inspect ⇒ String

: () -> String

Returns:

  • (String)


24623
24624
24625
# File 'lib/prism/node.rb', line 24623

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)


24669
24670
24671
# File 'lib/prism/node.rb', line 24669

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:



24646
24647
24648
24649
24650
# File 'lib/prism/node.rb', line 24646

def keyword_loc
  location = @keyword_loc
  return location if location.is_a?(Location)
  @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
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:



24657
24658
24659
# File 'lib/prism/node.rb', line 24657

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

#type ⇒ :next_node

See Node#type.

: () -> :next_node

Returns:

  • (:next_node)


24611
24612
24613
# File 'lib/prism/node.rb', line 24611

def type
  :next_node
end