Class: Prism::SourceFileNode

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

__FILE__
^^^^^^^^

Explore code sample

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, filepath) ⇒ SourceFileNode

Initialize a new SourceFileNode node.

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

Parameters:

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


30412
30413
30414
30415
30416
30417
30418
# File 'lib/prism/node.rb', line 30412

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

Class Method Details

.type ⇒ :source_file_node

See Node.type.

: () -> :source_file_node

Returns:

  • (:source_file_node)


30496
30497
30498
# File 'lib/prism/node.rb', line 30496

def self.type
  :source_file_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


30554
30555
30556
30557
30558
# File 'lib/prism/node.rb', line 30554

def ===(other) # :nodoc:
  other.is_a?(SourceFileNode) &&
    (flags === other.flags) &&
    (filepath === other.filepath)
end

#accept(visitor) ⇒ Object

See Node.accept.

: (_Visitor visitor) -> untyped

Parameters:

Returns:

  • (Object)


30434
30435
30436
# File 'lib/prism/node.rb', line 30434

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

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

See Node.child_nodes.

: () -> Array

Returns:

  • (Array[node?])


30441
30442
30443
# File 'lib/prism/node.rb', line 30441

def child_nodes
  []
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


30457
30458
30459
# File 'lib/prism/node.rb', line 30457

def compact_child_nodes
  []
end

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

:call-seq:

copy(**fields) -> SourceFileNode

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

: (?node_id: Integer, ?location: Location, ?flags: Integer, ?filepath: String) -> SourceFileNode

Parameters:

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

Returns:



30467
30468
30469
# File 'lib/prism/node.rb', line 30467

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

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

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

Parameters:

  • keys (Array[Symbol], nil)

Returns:

  • (Hash[Symbol, untyped])


30474
30475
30476
30477
30478
30479
30480
30481
30482
30483
30484
# File 'lib/prism/node.rb', line 30474

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


30449
30450
30451
30452
# File 'lib/prism/node.rb', line 30449

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

end

#filepath ⇒ String

:call-seq:

filepath -> String

Represents the file path being parsed. This corresponds directly to the filepath option given to the various Prism.parse* APIs.

: () -> String

Returns:

  • (String)


30545
30546
30547
# File 'lib/prism/node.rb', line 30545

def filepath
  @filepath
end

#forced_binary_encoding? ⇒ Boolean

:category: Flags internal bytes forced the encoding to binary

: () -> bool

Returns:

  • (Boolean)


30519
30520
30521
# File 'lib/prism/node.rb', line 30519

def forced_binary_encoding?
  flags.anybits?(StringFlags::FORCED_BINARY_ENCODING)
end

#forced_utf8_encoding? ⇒ Boolean

:category: Flags internal bytes forced the encoding to UTF-8

: () -> bool

Returns:

  • (Boolean)


30511
30512
30513
# File 'lib/prism/node.rb', line 30511

def forced_utf8_encoding?
  flags.anybits?(StringFlags::FORCED_UTF8_ENCODING)
end

#frozen? ⇒ Boolean

:category: Flags frozen by virtue of a frozen_string_literal: true comment or --enable-frozen-string-literal

: () -> bool

Returns:

  • (Boolean)


30527
30528
30529
# File 'lib/prism/node.rb', line 30527

def frozen?
  flags.anybits?(StringFlags::FROZEN)
end

#inspect ⇒ String

: () -> String

Returns:

  • (String)


30501
30502
30503
# File 'lib/prism/node.rb', line 30501

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

#mutable? ⇒ Boolean

:category: Flags mutable by virtue of a frozen_string_literal: false comment or --disable-frozen-string-literal

: () -> bool

Returns:

  • (Boolean)


30535
30536
30537
# File 'lib/prism/node.rb', line 30535

def mutable?
  flags.anybits?(StringFlags::MUTABLE)
end

#type ⇒ :source_file_node

See Node#type.

: () -> :source_file_node

Returns:

  • (:source_file_node)


30489
30490
30491
# File 'lib/prism/node.rb', line 30489

def type
  :source_file_node
end