Skip to content

Commit 68087ab

Browse files
committed
[DOC] Doc for StringIO.getc
1 parent 15a2567 commit 68087ab

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

doc/stringio/getc.rdoc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Reads and returns the next character from the stream:
1+
Reads and returns the next character (or byte; see below) from the stream:
22

33
strio = StringIO.new('foo')
44
strio.getc # => "f"
@@ -20,4 +20,15 @@ Returns characters, not bytes:
2020
strio.getc # => "こ"
2121
strio.getc # => "ん"
2222

23+
In each of the examples above, the stream is positioned at the beginning of a character;
24+
in other cases that need not be true:
25+
26+
strio = StringIO.new('こんにちは') # Five 3-byte characters.
27+
strio.pos = 3 # => 3 # At beginning of second character; returns character.
28+
strio.getc # => "ん"
29+
strio.pos = 4 # => 4 # At second byte of second character; returns byte.
30+
strio.getc # => "\x82"
31+
strio.pos = 5 # => 5 # At third byte of second character; returns byte.
32+
strio.getc # => "\x93"
33+
2334
Related: StringIO.getbyte.

ext/stringio/stringio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ strio_each_byte(VALUE self)
956956

957957
/*
958958
* call-seq:
959-
* getc -> character or nil
959+
* getc -> character, byte, or nil
960960
*
961961
* :include: stringio/getc.rdoc
962962
*

0 commit comments

Comments
 (0)