[ruby/stringio] [DOC] Doc for StringIO.getc

(https://github.com/ruby/stringio/pull/163)

https://github.com/ruby/stringio/commit/a126fe252f
This commit is contained in:
Burdette Lamar 2025-11-04 17:57:25 -06:00 committed by git
parent a0376eb2cc
commit 554a78daab
2 changed files with 37 additions and 3 deletions

34
doc/stringio/getc.rdoc Normal file
View File

@ -0,0 +1,34 @@
Reads and returns the next character (or byte; see below) from the stream:
strio = StringIO.new('foo')
strio.getc # => "f"
strio.getc # => "o"
strio.getc # => "o"
Returns +nil+ if at end-of-stream:
strio.eof? # => true
strio.getc # => nil
Returns characters, not bytes:
strio = StringIO.new('тест')
strio.getc # => "т"
strio.getc # => "е"
strio = StringIO.new('こんにちは')
strio.getc # => "こ"
strio.getc # => "ん"
In each of the examples above, the stream is positioned at the beginning of a character;
in other cases that need not be true:
strio = StringIO.new('こんにちは') # Five 3-byte characters.
strio.pos = 3 # => 3 # At beginning of second character; returns character.
strio.getc # => "ん"
strio.pos = 4 # => 4 # At second byte of second character; returns byte.
strio.getc # => "\x82"
strio.pos = 5 # => 5 # At third byte of second character; returns byte.
strio.getc # => "\x93"
Related: StringIO.getbyte.

View File

@ -964,10 +964,10 @@ strio_each_byte(VALUE self)
/*
* call-seq:
* getc -> character or nil
* getc -> character, byte, or nil
*
* :include: stringio/getc.rdoc
*
* Reads and returns the next character from the stream;
* see {Character IO}[rdoc-ref:IO@Character+IO].
*/
static VALUE
strio_getc(VALUE self)