Class: Prism::InterpolatedSymbolNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::InterpolatedSymbolNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents a symbol literal that contains interpolation.
:"foo #{bar} baz"
^^^^^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#closing_loc ⇒ Object
readonly
attr_reader closing_loc: Location?.
-
#opening_loc ⇒ Object
readonly
attr_reader opening_loc: Location?.
-
#parts ⇒ Object
readonly
attr_reader parts: Array.
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#closing ⇒ Object
def closing: () -> String?.
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#copy(**params) ⇒ Object
def copy: (**params) -> InterpolatedSymbolNode.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(opening_loc, parts, closing_loc, location) ⇒ InterpolatedSymbolNode
constructor
def initialize: (opening_loc: Location?, parts: Array, closing_loc: Location?, location: Location) -> void.
- #inspect(inspector = NodeInspector.new) ⇒ Object
-
#opening ⇒ Object
def opening: () -> String?.
- #set_newline_flag(newline_marked) ⇒ Object
-
#type ⇒ Object
Sometimes you want to check an instance of a node against a list of classes to see what kind of behavior to perform.
Constructor Details
#initialize(opening_loc, parts, closing_loc, location) ⇒ InterpolatedSymbolNode
def initialize: (opening_loc: Location?, parts: Array, closing_loc: Location?, location: Location) -> void
8209 8210 8211 8212 8213 8214 |
# File 'lib/prism/node.rb', line 8209 def initialize(opening_loc, parts, closing_loc, location) @opening_loc = opening_loc @parts = parts @closing_loc = closing_loc @location = location end |
Instance Attribute Details
#closing_loc ⇒ Object (readonly)
attr_reader closing_loc: Location?
8206 8207 8208 |
# File 'lib/prism/node.rb', line 8206 def closing_loc @closing_loc end |
#opening_loc ⇒ Object (readonly)
attr_reader opening_loc: Location?
8200 8201 8202 |
# File 'lib/prism/node.rb', line 8200 def opening_loc @opening_loc end |
#parts ⇒ Object (readonly)
attr_reader parts: Array
8203 8204 8205 |
# File 'lib/prism/node.rb', line 8203 def parts @parts end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
8217 8218 8219 |
# File 'lib/prism/node.rb', line 8217 def accept(visitor) visitor.visit_interpolated_symbol_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
8227 8228 8229 |
# File 'lib/prism/node.rb', line 8227 def child_nodes [*parts] end |
#closing ⇒ Object
def closing: () -> String?
8265 8266 8267 |
# File 'lib/prism/node.rb', line 8265 def closing closing_loc&.slice end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
8237 8238 8239 |
# File 'lib/prism/node.rb', line 8237 def comment_targets [*opening_loc, *parts, *closing_loc] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
8232 8233 8234 |
# File 'lib/prism/node.rb', line 8232 def compact_child_nodes [*parts] end |
#copy(**params) ⇒ Object
def copy: (**params) -> InterpolatedSymbolNode
8242 8243 8244 8245 8246 8247 8248 8249 |
# File 'lib/prism/node.rb', line 8242 def copy(**params) InterpolatedSymbolNode.new( params.fetch(:opening_loc) { opening_loc }, params.fetch(:parts) { parts }, params.fetch(:closing_loc) { closing_loc }, params.fetch(:location) { location }, ) end |
#deconstruct_keys(keys) ⇒ Object
8255 8256 8257 |
# File 'lib/prism/node.rb', line 8255 def deconstruct_keys(keys) { opening_loc: opening_loc, parts: parts, closing_loc: closing_loc, location: location } end |
#inspect(inspector = NodeInspector.new) ⇒ Object
8269 8270 8271 8272 8273 8274 8275 |
# File 'lib/prism/node.rb', line 8269 def inspect(inspector = NodeInspector.new) inspector << inspector.header(self) inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" inspector << "├── parts: #{inspector.list("#{inspector.prefix}│ ", parts)}" inspector << "└── closing_loc: #{inspector.location(closing_loc)}\n" inspector.to_str end |
#opening ⇒ Object
def opening: () -> String?
8260 8261 8262 |
# File 'lib/prism/node.rb', line 8260 def opening opening_loc&.slice end |
#set_newline_flag(newline_marked) ⇒ Object
8221 8222 8223 8224 |
# File 'lib/prism/node.rb', line 8221 def set_newline_flag(newline_marked) first = parts.first first.set_newline_flag(newline_marked) if first end |
#type ⇒ Object
Sometimes you want to check an instance of a node against a list of classes to see what kind of behavior to perform. Usually this is done by calling ‘[cls1, cls2].include?(node.class)` or putting the node into a case statement and doing `case node; when cls1; when cls2; end`. Both of these approaches are relatively slow because of the constant lookups, method calls, and/or array allocations.
Instead, you can call #type, which will return to you a symbol that you can use for comparison. This is faster than the other approaches because it uses a single integer comparison, but also because if you’re on CRuby you can take advantage of the fact that case statements with all symbol keys will use a jump table.
def type: () -> Symbol
8291 8292 8293 |
# File 'lib/prism/node.rb', line 8291 def type :interpolated_symbol_node end |