Class: PrettierPrint::Buffer::StringBuffer
- Inherits:
-
Object
- Object
- PrettierPrint::Buffer::StringBuffer
- Defined in:
- lib/prettier_print.rb
Overview
This is an output buffer that wraps a string output object. It provides a trim! method that trims off trailing whitespace from the string using gsub!.
Instance Attribute Summary collapse
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
- #<<(object) ⇒ Object
-
#initialize(output = "".dup) ⇒ StringBuffer
constructor
A new instance of StringBuffer.
- #trim! ⇒ Object
Constructor Details
#initialize(output = "".dup) ⇒ StringBuffer
Returns a new instance of StringBuffer.
284 285 286 |
# File 'lib/prettier_print.rb', line 284 def initialize(output = "".dup) @output = output end |
Instance Attribute Details
#output ⇒ Object (readonly)
Returns the value of attribute output.
282 283 284 |
# File 'lib/prettier_print.rb', line 282 def output @output end |
Instance Method Details
#<<(object) ⇒ Object
288 289 290 |
# File 'lib/prettier_print.rb', line 288 def <<(object) @output << object end |
#trim! ⇒ Object
292 293 294 295 296 |
# File 'lib/prettier_print.rb', line 292 def trim! length = output.length output.gsub!(/[\t ]*\z/, "") length - output.length end |