Class: IO::Stream::StringBuffer

Inherits:
String
  • Object
show all
Defined in:
lib/io/stream/string_buffer.rb

Overview

A specialized string buffer for binary data with automatic encoding handling.

Constant Summary collapse

BINARY =
Encoding::BINARY

Instance Method Summary collapse

Constructor Details

#initializeStringBuffer

Initialize a new string buffer with binary encoding.



12
13
14
15
16
# File 'lib/io/stream/string_buffer.rb', line 12

def initialize
  super
  
  force_encoding(BINARY)
end

Instance Method Details

#<<(string) ⇒ Object Also known as: concat

Append a string to the buffer, converting to binary encoding if necessary.



21
22
23
24
25
26
27
28
29
# File 'lib/io/stream/string_buffer.rb', line 21

def << string
  if string.encoding == BINARY
    super(string)
  else
    super(string.b)
  end
  
  return self
end