Class: Prism::GlobalVariableReadNode

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

Overview

Represents referencing a global variable.

$foo
^^^^

Explore code sample

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, name) ⇒ GlobalVariableReadNode

Initialize a new GlobalVariableReadNode node.

: (Source source, Integer node_id, Location location, Integer flags, Symbol name) -> void

Parameters:

  • source (Source)
  • node_id (Integer)
  • location (Location)
  • flags (Integer)
  • name (Symbol)


14570
14571
14572
14573
14574
14575
14576
# File 'lib/prism/node.rb', line 14570

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

Class Method Details

.type ⇒ :global_variable_read_node

See Node.type.

: () -> :global_variable_read_node

Returns:

  • (:global_variable_read_node)


14654
14655
14656
# File 'lib/prism/node.rb', line 14654

def self.type
  :global_variable_read_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


14688
14689
14690
14691
# File 'lib/prism/node.rb', line 14688

def ===(other) # :nodoc:
  other.is_a?(GlobalVariableReadNode) &&
    (name === other.name)
end

#accept(visitor) ⇒ Object

See Node.accept.

: (_Visitor visitor) -> untyped

Parameters:

Returns:

  • (Object)


14592
14593
14594
# File 'lib/prism/node.rb', line 14592

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

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

See Node.child_nodes.

: () -> Array

Returns:

  • (Array[node?])


14599
14600
14601
# File 'lib/prism/node.rb', line 14599

def child_nodes
  []
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


14615
14616
14617
# File 'lib/prism/node.rb', line 14615

def compact_child_nodes
  []
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name) ⇒ GlobalVariableReadNode

:call-seq:

copy(**fields) -> GlobalVariableReadNode

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

: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol) -> GlobalVariableReadNode

Parameters:

  • node_id: (Integer) (defaults to: self.node_id)
  • location: (Location) (defaults to: self.location)
  • flags: (Integer) (defaults to: self.flags)
  • name: (Symbol) (defaults to: self.name)

Returns:



14625
14626
14627
# File 'lib/prism/node.rb', line 14625

def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name)
  GlobalVariableReadNode.new(source, node_id, location, flags, name)
end

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

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

Parameters:

  • keys (Array[Symbol], nil)

Returns:

  • (Hash[Symbol, untyped])


14632
14633
14634
14635
14636
14637
14638
14639
14640
14641
14642
# File 'lib/prism/node.rb', line 14632

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


14607
14608
14609
14610
# File 'lib/prism/node.rb', line 14607

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

end

#inspect ⇒ String

: () -> String

Returns:

  • (String)


14659
14660
14661
# File 'lib/prism/node.rb', line 14659

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

#name ⇒ Symbol

:call-seq:

name -> Symbol

The name of the global variable, which is a $ followed by an identifier. Alternatively, it can be one of the special global variables designated by a symbol.

$foo   # name `:$foo`

$_Test # name `:$_Test`

Explore code sample

: () -> Symbol

Returns:

  • (Symbol)


14679
14680
14681
# File 'lib/prism/node.rb', line 14679

def name
  @name
end

#type ⇒ :global_variable_read_node

See Node#type.

: () -> :global_variable_read_node

Returns:

  • (:global_variable_read_node)


14647
14648
14649
# File 'lib/prism/node.rb', line 14647

def type
  :global_variable_read_node
end