Class: Markbridge::AST::Text
Overview
Represents a text node (leaf node) in the AST. Text nodes contain the actual text content and cannot have children.
Instance Attribute Summary collapse
-
#text ⇒ String
readonly
The text content of this node.
Instance Method Summary collapse
-
#initialize(text) ⇒ Text
constructor
Create a new text node with the given content.
-
#merge(other) ⇒ Text
Merge another text node’s content into this one.
Constructor Details
#initialize(text) ⇒ Text
Create a new text node with the given content.
The text is copied into a fresh mutable buffer so that subsequent in-place mutations (e.g. via #merge) do not leak back to the caller’s original string.
27 28 29 |
# File 'lib/markbridge/ast/text.rb', line 27 def initialize(text) @text = text.dup end |
Instance Attribute Details
#text ⇒ String (readonly)
Returns the text content of this node.
18 19 20 |
# File 'lib/markbridge/ast/text.rb', line 18 def text @text end |
Instance Method Details
#merge(other) ⇒ Text
Merge another text node’s content into this one. This mutates the current text node by appending the other’s text.
36 37 38 39 |
# File 'lib/markbridge/ast/text.rb', line 36 def merge(other) @text << other.text self end |