Class: YARP::StringNode
- Inherits:
-
YARPNode
- Object
- YARPNode
- YARP::StringNode
- Defined in:
- lib/yarp/node.rb,
ext/yarp/api_node.c
Overview
Represents a string literal, a string contained within a ‘%w` list, or plain string content within an interpolated string.
"foo"
^^^^^
%w[foo]
^^^
"foo #{bar} baz"
^^^^ ^^^^
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].
-
#content ⇒ Object
def content: () -> String.
-
#copy(**params) ⇒ Object
def copy: (**params) -> StringNode.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(opening_loc, content_loc, closing_loc, unescaped, location) ⇒ StringNode
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?.
Constructor Details
#initialize(opening_loc, content_loc, closing_loc, unescaped, location) ⇒ StringNode
def initialize: (opening_loc: Location?, content_loc: Location, closing_loc: Location?, unescaped: String, location: Location) -> void
9626 9627 9628 9629 9630 9631 9632 |
# File 'lib/yarp/node.rb', line 9626 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?
9620 9621 9622 |
# File 'lib/yarp/node.rb', line 9620 def closing_loc @closing_loc end |
#content_loc ⇒ Object (readonly)
attr_reader content_loc: Location
9617 9618 9619 |
# File 'lib/yarp/node.rb', line 9617 def content_loc @content_loc end |
#opening_loc ⇒ Object (readonly)
attr_reader opening_loc: Location?
9614 9615 9616 |
# File 'lib/yarp/node.rb', line 9614 def opening_loc @opening_loc end |
#unescaped ⇒ Object (readonly)
attr_reader unescaped: String
9623 9624 9625 |
# File 'lib/yarp/node.rb', line 9623 def unescaped @unescaped end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
9635 9636 9637 |
# File 'lib/yarp/node.rb', line 9635 def accept(visitor) visitor.visit_string_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
9640 9641 9642 |
# File 'lib/yarp/node.rb', line 9640 def child_nodes [] end |
#closing ⇒ Object
def closing: () -> String?
9679 9680 9681 |
# File 'lib/yarp/node.rb', line 9679 def closing closing_loc&.slice end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
9645 9646 9647 |
# File 'lib/yarp/node.rb', line 9645 def comment_targets [*opening_loc, content_loc, *closing_loc] end |
#content ⇒ Object
def content: () -> String
9674 9675 9676 |
# File 'lib/yarp/node.rb', line 9674 def content content_loc.slice end |
#copy(**params) ⇒ Object
def copy: (**params) -> StringNode
9650 9651 9652 9653 9654 9655 9656 9657 9658 |
# File 'lib/yarp/node.rb', line 9650 def copy(**params) StringNode.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
9664 9665 9666 |
# File 'lib/yarp/node.rb', line 9664 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
9683 9684 9685 9686 9687 9688 9689 9690 |
# File 'lib/yarp/node.rb', line 9683 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?
9669 9670 9671 |
# File 'lib/yarp/node.rb', line 9669 def opening opening_loc&.slice end |