Class: Prism::SymbolNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::SymbolNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents a symbol literal or a symbol contained within a ‘%i` list.
:foo
^^^^
%i[foo]
^^^
Instance Attribute Summary collapse
-
#unescaped ⇒ Object
readonly
attr_reader unescaped: String.
Class Method Summary collapse
-
.type ⇒ Object
Return a symbol representation of this node type.
Instance Method Summary collapse
-
#===(other) ⇒ Object
Implements case-equality for the node.
-
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#closing ⇒ Object
def closing: () -> String?.
-
#closing_loc ⇒ Object
attr_reader closing_loc: Location?.
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, value_loc: self.value_loc, closing_loc: self.closing_loc, unescaped: self.unescaped) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?opening_loc: Location?, ?value_loc: Location?, ?closing_loc: Location?, ?unescaped: String) -> SymbolNode.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, opening_loc: Location?, value_loc: Location?, closing_loc: Location?, unescaped: String }.
-
#forced_binary_encoding? ⇒ Boolean
def forced_binary_encoding?: () -> bool.
-
#forced_us_ascii_encoding? ⇒ Boolean
def forced_us_ascii_encoding?: () -> bool.
-
#forced_utf8_encoding? ⇒ Boolean
def forced_utf8_encoding?: () -> bool.
-
#initialize(source, node_id, location, flags, opening_loc, value_loc, closing_loc, unescaped) ⇒ SymbolNode
constructor
Initialize a new SymbolNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#opening ⇒ Object
def opening: () -> String?.
-
#opening_loc ⇒ Object
attr_reader opening_loc: Location?.
-
#type ⇒ Object
Return a symbol representation of this node type.
-
#value ⇒ Object
def value: () -> String?.
-
#value_loc ⇒ Object
attr_reader value_loc: Location?.
Constructor Details
#initialize(source, node_id, location, flags, opening_loc, value_loc, closing_loc, unescaped) ⇒ SymbolNode
Initialize a new SymbolNode node.
15594 15595 15596 15597 15598 15599 15600 15601 15602 15603 |
# File 'lib/prism/node.rb', line 15594 def initialize(source, node_id, location, flags, opening_loc, value_loc, closing_loc, unescaped) @source = source @node_id = node_id @location = location @flags = flags @opening_loc = opening_loc @value_loc = value_loc @closing_loc = closing_loc @unescaped = unescaped end |
Instance Attribute Details
#unescaped ⇒ Object (readonly)
attr_reader unescaped: String
15693 15694 15695 |
# File 'lib/prism/node.rb', line 15693 def unescaped @unescaped end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
15721 15722 15723 |
# File 'lib/prism/node.rb', line 15721 def self.type :symbol_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.
15727 15728 15729 15730 15731 15732 15733 15734 |
# File 'lib/prism/node.rb', line 15727 def ===(other) other.is_a?(SymbolNode) && (flags === other.flags) && (opening_loc.nil? == other.opening_loc.nil?) && (value_loc.nil? == other.value_loc.nil?) && (closing_loc.nil? == other.closing_loc.nil?) && (unescaped === other.unescaped) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
15606 15607 15608 |
# File 'lib/prism/node.rb', line 15606 def accept(visitor) visitor.visit_symbol_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
15611 15612 15613 |
# File 'lib/prism/node.rb', line 15611 def child_nodes [] end |
#closing ⇒ Object
def closing: () -> String?
15706 15707 15708 |
# File 'lib/prism/node.rb', line 15706 def closing closing_loc&.slice end |
#closing_loc ⇒ Object
attr_reader closing_loc: Location?
15680 15681 15682 15683 15684 15685 15686 15687 15688 15689 15690 |
# File 'lib/prism/node.rb', line 15680 def closing_loc location = @closing_loc case location when nil nil when Location location else @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
15621 15622 15623 |
# File 'lib/prism/node.rb', line 15621 def comment_targets [*opening_loc, *value_loc, *closing_loc] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
15616 15617 15618 |
# File 'lib/prism/node.rb', line 15616 def compact_child_nodes [] end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, value_loc: self.value_loc, closing_loc: self.closing_loc, unescaped: self.unescaped) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?opening_loc: Location?, ?value_loc: Location?, ?closing_loc: Location?, ?unescaped: String) -> SymbolNode
15626 15627 15628 |
# File 'lib/prism/node.rb', line 15626 def copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, value_loc: self.value_loc, closing_loc: self.closing_loc, unescaped: self.unescaped) SymbolNode.new(source, node_id, location, flags, opening_loc, value_loc, closing_loc, unescaped) end |
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, opening_loc: Location?, value_loc: Location?, closing_loc: Location?, unescaped: String }
15634 15635 15636 |
# File 'lib/prism/node.rb', line 15634 def deconstruct_keys(keys) { node_id: node_id, location: location, opening_loc: opening_loc, value_loc: value_loc, closing_loc: closing_loc, unescaped: unescaped } end |
#forced_binary_encoding? ⇒ Boolean
def forced_binary_encoding?: () -> bool
15644 15645 15646 |
# File 'lib/prism/node.rb', line 15644 def forced_binary_encoding? flags.anybits?(SymbolFlags::FORCED_BINARY_ENCODING) end |
#forced_us_ascii_encoding? ⇒ Boolean
def forced_us_ascii_encoding?: () -> bool
15649 15650 15651 |
# File 'lib/prism/node.rb', line 15649 def forced_us_ascii_encoding? flags.anybits?(SymbolFlags::FORCED_US_ASCII_ENCODING) end |
#forced_utf8_encoding? ⇒ Boolean
def forced_utf8_encoding?: () -> bool
15639 15640 15641 |
# File 'lib/prism/node.rb', line 15639 def forced_utf8_encoding? flags.anybits?(SymbolFlags::FORCED_UTF8_ENCODING) end |
#inspect ⇒ Object
def inspect -> String
15711 15712 15713 |
# File 'lib/prism/node.rb', line 15711 def inspect InspectVisitor.compose(self) end |
#opening ⇒ Object
def opening: () -> String?
15696 15697 15698 |
# File 'lib/prism/node.rb', line 15696 def opening opening_loc&.slice end |
#opening_loc ⇒ Object
attr_reader opening_loc: Location?
15654 15655 15656 15657 15658 15659 15660 15661 15662 15663 15664 |
# File 'lib/prism/node.rb', line 15654 def opening_loc location = @opening_loc case location when nil nil when Location location else @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
15716 15717 15718 |
# File 'lib/prism/node.rb', line 15716 def type :symbol_node end |
#value ⇒ Object
def value: () -> String?
15701 15702 15703 |
# File 'lib/prism/node.rb', line 15701 def value value_loc&.slice end |
#value_loc ⇒ Object
attr_reader value_loc: Location?
15667 15668 15669 15670 15671 15672 15673 15674 15675 15676 15677 |
# File 'lib/prism/node.rb', line 15667 def value_loc location = @value_loc case location when nil nil when Location location else @value_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |