Class: SocksTunnel::Buffer

Inherits:
Object
  • Object
show all
Defined in:
lib/socks_tunnel/buffer.rb

Instance Method Summary collapse

Constructor Details

#initializeBuffer

Returns a new instance of Buffer.



3
4
5
# File 'lib/socks_tunnel/buffer.rb', line 3

def initialize
  @buffer_data = ''
end

Instance Method Details

#<<(data) ⇒ Object



7
8
9
# File 'lib/socks_tunnel/buffer.rb', line 7

def <<(data)
  @buffer_data << data
end

#clearObject



29
30
31
# File 'lib/socks_tunnel/buffer.rb', line 29

def clear
  @buffer_data = ''
end

#eachObject



11
12
13
14
15
16
17
18
# File 'lib/socks_tunnel/buffer.rb', line 11

def each
  loop do
    fore, rest = @buffer_data.split(Config.delimiter, 2)
    break unless rest
    yield fore
    @buffer_data = rest
  end
end

#shiftObject



20
21
22
23
24
25
26
27
# File 'lib/socks_tunnel/buffer.rb', line 20

def shift
  fore, rest = @buffer_data.split(Config.delimiter, 2)
  if rest
    @buffer_data = rest
    return fore
  end
  nil
end