Class: Prism::XStringNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::XStringNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents an xstring literal with no interpolation.
`foo`
^^^^^
Instance Attribute Summary collapse
-
#closing_loc ⇒ Object
readonly
attr_reader closing_loc: Location.
-
#content_loc ⇒ Object
readonly
attr_reader content_loc: Location.
-
#opening_loc ⇒ Object
readonly
attr_reader opening_loc: Location.
-
#unescaped ⇒ Object
readonly
attr_reader unescaped: String.
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.
-
#content ⇒ Object
def content: () -> String.
-
#copy(**params) ⇒ Object
def copy: (**params) -> XStringNode.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(opening_loc, content_loc, closing_loc, unescaped, location) ⇒ XStringNode
constructor
def initialize: (opening_loc: Location, content_loc: Location, closing_loc: Location, unescaped: String, location: Location) -> void.
- #inspect(inspector = NodeInspector.new) ⇒ Object
-
#opening ⇒ Object
def opening: () -> String.
-
#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, content_loc, closing_loc, unescaped, location) ⇒ XStringNode
def initialize: (opening_loc: Location, content_loc: Location, closing_loc: Location, unescaped: String, location: Location) -> void
14273 14274 14275 14276 14277 14278 14279 |
# File 'lib/prism/node.rb', line 14273 def initialize(opening_loc, content_loc, closing_loc, unescaped, location) @opening_loc = opening_loc @content_loc = content_loc @closing_loc = closing_loc @unescaped = unescaped @location = location end |
Instance Attribute Details
#closing_loc ⇒ Object (readonly)
attr_reader closing_loc: Location
14267 14268 14269 |
# File 'lib/prism/node.rb', line 14267 def closing_loc @closing_loc end |
#content_loc ⇒ Object (readonly)
attr_reader content_loc: Location
14264 14265 14266 |
# File 'lib/prism/node.rb', line 14264 def content_loc @content_loc end |
#opening_loc ⇒ Object (readonly)
attr_reader opening_loc: Location
14261 14262 14263 |
# File 'lib/prism/node.rb', line 14261 def opening_loc @opening_loc end |
#unescaped ⇒ Object (readonly)
attr_reader unescaped: String
14270 14271 14272 |
# File 'lib/prism/node.rb', line 14270 def unescaped @unescaped end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
14282 14283 14284 |
# File 'lib/prism/node.rb', line 14282 def accept(visitor) visitor.visit_x_string_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
14287 14288 14289 |
# File 'lib/prism/node.rb', line 14287 def child_nodes [] end |
#closing ⇒ Object
def closing: () -> String
14331 14332 14333 |
# File 'lib/prism/node.rb', line 14331 def closing closing_loc.slice end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
14297 14298 14299 |
# File 'lib/prism/node.rb', line 14297 def comment_targets [opening_loc, content_loc, closing_loc] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
14292 14293 14294 |
# File 'lib/prism/node.rb', line 14292 def compact_child_nodes [] end |
#content ⇒ Object
def content: () -> String
14326 14327 14328 |
# File 'lib/prism/node.rb', line 14326 def content content_loc.slice end |
#copy(**params) ⇒ Object
def copy: (**params) -> XStringNode
14302 14303 14304 14305 14306 14307 14308 14309 14310 |
# File 'lib/prism/node.rb', line 14302 def copy(**params) XStringNode.new( params.fetch(:opening_loc) { opening_loc }, params.fetch(:content_loc) { content_loc }, params.fetch(:closing_loc) { closing_loc }, params.fetch(:unescaped) { unescaped }, params.fetch(:location) { location }, ) end |
#deconstruct_keys(keys) ⇒ Object
14316 14317 14318 |
# File 'lib/prism/node.rb', line 14316 def deconstruct_keys(keys) { opening_loc: opening_loc, content_loc: content_loc, closing_loc: closing_loc, unescaped: unescaped, location: location } end |
#inspect(inspector = NodeInspector.new) ⇒ Object
14335 14336 14337 14338 14339 14340 14341 14342 |
# File 'lib/prism/node.rb', line 14335 def inspect(inspector = NodeInspector.new) inspector << inspector.header(self) inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" inspector << "├── content_loc: #{inspector.location(content_loc)}\n" inspector << "├── closing_loc: #{inspector.location(closing_loc)}\n" inspector << "└── unescaped: #{unescaped.inspect}\n" inspector.to_str end |
#opening ⇒ Object
def opening: () -> String
14321 14322 14323 |
# File 'lib/prism/node.rb', line 14321 def opening opening_loc.slice 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
14358 14359 14360 |
# File 'lib/prism/node.rb', line 14358 def type :x_string_node end |