Class: Prism::ConstantReadNode

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

Overview

Represents referencing a constant.

Foo
^^^

Explore code sample

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initialize a new ConstantReadNode 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)


10235
10236
10237
10238
10239
10240
10241
# File 'lib/prism/node.rb', line 10235

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 ⇒ :constant_read_node

See Node.type.

: () -> :constant_read_node

Returns:

  • (:constant_read_node)


10319
10320
10321
# File 'lib/prism/node.rb', line 10319

def self.type
  :constant_read_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


10353
10354
10355
10356
# File 'lib/prism/node.rb', line 10353

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

#accept(visitor) ⇒ Object

See Node.accept.

: (_Visitor visitor) -> untyped

Parameters:

Returns:

  • (Object)


10257
10258
10259
# File 'lib/prism/node.rb', line 10257

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

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

See Node.child_nodes.

: () -> Array

Returns:

  • (Array[node?])


10264
10265
10266
# File 'lib/prism/node.rb', line 10264

def child_nodes
  []
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


10280
10281
10282
# File 'lib/prism/node.rb', line 10280

def compact_child_nodes
  []
end

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

:call-seq:

copy(**fields) -> ConstantReadNode

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

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

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:



10290
10291
10292
# File 'lib/prism/node.rb', line 10290

def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name)
  ConstantReadNode.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])


10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
# File 'lib/prism/node.rb', line 10297

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)


10272
10273
10274
10275
# File 'lib/prism/node.rb', line 10272

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

end

#full_name ⇒ String

Returns the full name of this constant. For example: "Foo"

: () -> String

Returns:

  • (String)


193
194
195
# File 'lib/prism/node_ext.rb', line 193

def full_name
  name.to_s
end

#full_name_parts ⇒ Array[Symbol]

Returns the list of parts for the full name of this constant. For example: [:Foo]

: () -> Array

Returns:

  • (Array[Symbol])


186
187
188
# File 'lib/prism/node_ext.rb', line 186

def full_name_parts
  [name]
end

#inspect ⇒ String

: () -> String

Returns:

  • (String)


10324
10325
10326
# File 'lib/prism/node.rb', line 10324

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

#name ⇒ Symbol

:call-seq:

name -> Symbol

The name of the constant.

X              # name `:X`

SOME_CONSTANT  # name `:SOME_CONSTANT`

Explore code sample

: () -> Symbol

Returns:

  • (Symbol)


10344
10345
10346
# File 'lib/prism/node.rb', line 10344

def name
  @name
end

#type ⇒ :constant_read_node

See Node#type.

: () -> :constant_read_node

Returns:

  • (:constant_read_node)


10312
10313
10314
# File 'lib/prism/node.rb', line 10312

def type
  :constant_read_node
end