Class: PrettyPrint::Text
- Inherits:
-
Object
- Object
- PrettyPrint::Text
- Defined in:
- lib/syntax_tree/prettyprint.rb
Overview
A node in the print tree that represents plain content that cannot be broken up (by default this assumes strings, but it can really be anything).
Instance Attribute Summary collapse
-
#objects ⇒ Object
readonly
Returns the value of attribute objects.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #add(object: "", width: object.length) ⇒ Object
-
#initialize ⇒ Text
constructor
A new instance of Text.
- #pretty_print(q) ⇒ Object
Constructor Details
#initialize ⇒ Text
Returns a new instance of Text.
239 240 241 242 |
# File 'lib/syntax_tree/prettyprint.rb', line 239 def initialize @objects = [] @width = 0 end |
Instance Attribute Details
#objects ⇒ Object (readonly)
Returns the value of attribute objects.
237 238 239 |
# File 'lib/syntax_tree/prettyprint.rb', line 237 def objects @objects end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
237 238 239 |
# File 'lib/syntax_tree/prettyprint.rb', line 237 def width @width end |
Instance Method Details
#add(object: "", width: object.length) ⇒ Object
244 245 246 247 |
# File 'lib/syntax_tree/prettyprint.rb', line 244 def add(object: "", width: object.length) @objects << object @width += width end |
#pretty_print(q) ⇒ Object
249 250 251 252 253 |
# File 'lib/syntax_tree/prettyprint.rb', line 249 def pretty_print(q) q.group(2, "text([", "])") do q.seplist(objects) { |object| q.pp(object) } end end |