11Replaces one or more bytes at position +pos+
22with bytes of the given argument;
3+ advances the position by the count of bytes written;
34returns the argument.
45
56\StringIO object for 1-byte characters.
67
78 strio = StringIO.new('foo')
9+ strio.pos # => 0
810
911With 1-byte argument, replaces one byte:
1012
1113 strio.putc('b')
1214 strio.string # => "boo"
15+ strio.pos # => 1
1316 strio.putc('a') # => "a"
1417 strio.string # => "bao"
18+ strio.pos # => 2
1519 strio.putc('r') # => "r"
1620 strio.string # => "bar"
21+ strio.pos # => 3
1722 strio.putc('n') # => "n"
1823 strio.string # => "barn"
24+ strio.pos # => 4
1925
2026Fills with null characters if necessary:
2127
2228 strio.pos = 6
2329 strio.putc('x') # => "x"
2430 strio.string # => "barn\u0000\u0000x"
31+ strio.pos # => 7
2532
2633With integer argument, replaces one byte with the low-order byte of the integer:
2734
@@ -46,13 +53,15 @@ With integer argument, replaces one byte with the low-order byte of the integer:
4653With 1-byte argument, replaces one byte of the string:
4754
4855 strio.putc(' ') # 1-byte ascii space.
56+ strio.pos # => 1
4957 strio.string # => " \xB1βγδε"
5058 strio.string.b # => " \xB1\xCE\xB2\xCE\xB3\xCE\xB4\xCE\xB5"
5159 strio.string.bytesize # => 10
5260 strio.string.chars # => [" ", "\xB1", "β", "γ", "δ", "ε"]
5361 strio.string.size # => 6
5462
5563 strio.putc(' ')
64+ strio.pos # => 2
5665 strio.string # => " βγδε"
5766 strio.string.b # => " \xCE\xB2\xCE\xB3\xCE\xB4\xCE\xB5"
5867 strio.string.bytesize # => 10
@@ -63,6 +72,7 @@ With 2-byte argument, replaces two bytes of the string:
6372
6473 strio.rewind
6574 strio.putc('α')
75+ strio.pos # => 2
6676 strio.string # => "αβγδε"
6777 strio.string.b # => "\xCE\xB1\xCE\xB2\xCE\xB3\xCE\xB4\xCE\xB5"
6878 strio.string.bytesize # => 10
0 commit comments