Class: Prism::SourceEncodingNode

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

__ENCODING__
^^^^^^^^^^^^

Explore code sample

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags) ⇒ SourceEncodingNode

Initialize a new SourceEncodingNode node.

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

Parameters:

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


30295
30296
30297
30298
30299
30300
# File 'lib/prism/node.rb', line 30295

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

Class Method Details

.type ⇒ :source_encoding_node

See Node.type.

: () -> :source_encoding_node

Returns:

  • (:source_encoding_node)


30377
30378
30379
# File 'lib/prism/node.rb', line 30377

def self.type
  :source_encoding_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


30393
30394
30395
# File 'lib/prism/node.rb', line 30393

def ===(other) # :nodoc:
  other.is_a?(SourceEncodingNode)
end

#accept(visitor) ⇒ Object

See Node.accept.

: (_Visitor visitor) -> untyped

Parameters:

Returns:

  • (Object)


30316
30317
30318
# File 'lib/prism/node.rb', line 30316

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

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

See Node.child_nodes.

: () -> Array

Returns:

  • (Array[node?])


30323
30324
30325
# File 'lib/prism/node.rb', line 30323

def child_nodes
  []
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


30339
30340
30341
# File 'lib/prism/node.rb', line 30339

def compact_child_nodes
  []
end

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

:call-seq:

copy(**fields) -> SourceEncodingNode

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

: (?node_id: Integer, ?location: Location, ?flags: Integer, ) -> SourceEncodingNode

Parameters:

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

Returns:



30349
30350
30351
# File 'lib/prism/node.rb', line 30349

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

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

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

Parameters:

  • keys (Array[Symbol], nil)

Returns:

  • (Hash[Symbol, untyped])


30356
30357
30358
30359
30360
30361
30362
30363
30364
30365
# File 'lib/prism/node.rb', line 30356

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


30331
30332
30333
30334
# File 'lib/prism/node.rb', line 30331

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

end

#inspect ⇒ String

: () -> String

Returns:

  • (String)


30382
30383
30384
# File 'lib/prism/node.rb', line 30382

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

#type ⇒ :source_encoding_node

See Node#type.

: () -> :source_encoding_node

Returns:

  • (:source_encoding_node)


30370
30371
30372
# File 'lib/prism/node.rb', line 30370

def type
  :source_encoding_node
end