Class: StringIO

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.allocate(size) ⇒ Object



10
11
12
# File 'lib/stringio_additions.rb', line 10

def self.allocate(size)
  new "\0" * size
end

Instance Method Details

#byteObject



14
15
16
# File 'lib/stringio_additions.rb', line 14

def byte
  read(1)[0].ord
end

#cstringObject



42
43
44
# File 'lib/stringio_additions.rb', line 42

def cstring
  gets("\0")[0..-2]
end

#floatObject



18
19
20
# File 'lib/stringio_additions.rb', line 18

def float
  read(4).unpack('e')[0]
end

#getObject



22
23
24
# File 'lib/stringio_additions.rb', line 22

def get
  read remaining
end

#longObject



26
27
28
# File 'lib/stringio_additions.rb', line 26

def long
  read(4).unpack('V')[0]
end

#remainingObject



30
31
32
# File 'lib/stringio_additions.rb', line 30

def remaining
  size - pos
end

#shortObject



34
35
36
# File 'lib/stringio_additions.rb', line 34

def short
  read(2).unpack('v')[0]
end

#signed_longObject



38
39
40
# File 'lib/stringio_additions.rb', line 38

def signed_long
  read(4).unpack('l')[0]
end