Class: Prism::SourceFileNode

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

Overview

Represents the use of the ‘__FILE__` keyword.

__FILE__
^^^^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initialize a new SourceFileNode node.



14974
14975
14976
14977
14978
14979
14980
# File 'lib/prism/node.rb', line 14974

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

Instance Attribute Details

#filepathObject (readonly)

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



15036
15037
15038
# File 'lib/prism/node.rb', line 15036

def filepath
  @filepath
end

Class Method Details

.typeObject

Return a symbol representation of this node type. See ‘Node::type`.



15049
15050
15051
# File 'lib/prism/node.rb', line 15049

def self.type
  :source_file_node
end

Instance Method Details

#===(other) ⇒ Object

Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.



15055
15056
15057
15058
15059
# File 'lib/prism/node.rb', line 15055

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

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



14983
14984
14985
# File 'lib/prism/node.rb', line 14983

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



14988
14989
14990
# File 'lib/prism/node.rb', line 14988

def child_nodes
  []
end

#comment_targetsObject

def comment_targets: () -> Array[Node | Location]



14998
14999
15000
# File 'lib/prism/node.rb', line 14998

def comment_targets
  [] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



14993
14994
14995
# File 'lib/prism/node.rb', line 14993

def compact_child_nodes
  []
end

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

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



15003
15004
15005
# File 'lib/prism/node.rb', line 15003

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) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, filepath: String }



15011
15012
15013
# File 'lib/prism/node.rb', line 15011

def deconstruct_keys(keys)
  { node_id: node_id, location: location, filepath: filepath }
end

#forced_binary_encoding?Boolean

def forced_binary_encoding?: () -> bool

Returns:

  • (Boolean)


15021
15022
15023
# File 'lib/prism/node.rb', line 15021

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

#forced_utf8_encoding?Boolean

def forced_utf8_encoding?: () -> bool

Returns:

  • (Boolean)


15016
15017
15018
# File 'lib/prism/node.rb', line 15016

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

#frozen?Boolean

def frozen?: () -> bool

Returns:

  • (Boolean)


15026
15027
15028
# File 'lib/prism/node.rb', line 15026

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

#inspectObject

def inspect -> String



15039
15040
15041
# File 'lib/prism/node.rb', line 15039

def inspect
  InspectVisitor.compose(self)
end

#mutable?Boolean

def mutable?: () -> bool

Returns:

  • (Boolean)


15031
15032
15033
# File 'lib/prism/node.rb', line 15031

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

#typeObject

Return a symbol representation of this node type. See ‘Node#type`.



15044
15045
15046
# File 'lib/prism/node.rb', line 15044

def type
  :source_file_node
end