Class: PrettierPrint::Buffer::StringBuffer

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#outputObject (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