From 2a6e4a7503f49bc4ebcd7babeb8297d8dfda52e9 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Mon, 27 Oct 2025 18:40:47 +0100 Subject: [PATCH 1/2] [DOC] Doc for StringIO#each_char --- ext/stringio/stringio.c | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index 5c6568a2..4e76229a 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -1162,12 +1162,44 @@ strio_readbyte(VALUE self) /* * call-seq: - * each_char {|c| ... } -> self + * each_char {|char| ... } -> self * * With a block given, calls the block with each remaining character in the stream; - * see {Character IO}[rdoc-ref:IO@Character+IO]. - * - * With no block given, returns an enumerator. + * positions the stream at end-of-file; + * returns +self+: + * + * chars = [] + * strio = StringIO.new('hello') + * strio.each_char {|char| chars.push(char) } + * strio.eof? # => true + * chars # => ["h", "e", "l", "l", "o"] + * chars = [] + * strio = StringIO.new('тест') + * strio.each_char {|char| chars.push(char) } + * chars # => ["т", "е", "с", "т"] + * chars = [] + * strio = StringIO.new('こんにちは') + * strio.each_char {|char| chars.push(char) } + * chars # => ["こ", "ん", "に", "ち", "は"] + * + * Stream position matters: + * + * chars = [] + * strio = StringIO.new('こんにちは') + * strio.getc # => "こ" + * strio.pos # => 3 # 3-byte character was read. + * strio.each_char {|char| chars.push(char) } + * chars # => ["ん", "に", "ち", "は"] + * + * When at end-of-stream does not call the block: + * + * strio.eof? # => true + * strio.each_char {|char| fail 'Boo!' } + * strio.eof? # => true + * + * With no block given, returns a new {Enumerator}[https://docs.ruby-lang.org/en/master/Enumerator.html]. + * + * Related: StringIO.each_byte, StringIO.each_codepoint, StringIO.each_line. */ static VALUE strio_each_char(VALUE self) From e9ff28398340ca974afdd7effacb3de667f24e45 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Tue, 28 Oct 2025 12:05:57 +0900 Subject: [PATCH 2/2] Fix separator --- ext/stringio/stringio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index 4e76229a..b5bd92fa 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -1199,7 +1199,7 @@ strio_readbyte(VALUE self) * * With no block given, returns a new {Enumerator}[https://docs.ruby-lang.org/en/master/Enumerator.html]. * - * Related: StringIO.each_byte, StringIO.each_codepoint, StringIO.each_line. + * Related: StringIO#each_byte, StringIO#each_codepoint, StringIO#each_line. */ static VALUE strio_each_char(VALUE self)