@@ -1194,12 +1194,44 @@ strio_readbyte(VALUE self)
11941194
11951195/*
11961196 * call-seq:
1197- * each_char {|c | ... } -> self
1197+ * each_char {|char | ... } -> self
11981198 *
11991199 * With a block given, calls the block with each remaining character in the stream;
1200- * see {Character IO}[rdoc-ref:IO@Character+IO].
1200+ * positions the stream at end-of-file;
1201+ * returns +self+:
12011202 *
1202- * With no block given, returns an enumerator.
1203+ * chars = []
1204+ * strio = StringIO.new('hello')
1205+ * strio.each_char {|char| chars.push(char) }
1206+ * strio.eof? # => true
1207+ * chars # => ["h", "e", "l", "l", "o"]
1208+ * chars = []
1209+ * strio = StringIO.new('тест')
1210+ * strio.each_char {|char| chars.push(char) }
1211+ * chars # => ["т", "е", "с", "т"]
1212+ * chars = []
1213+ * strio = StringIO.new('こんにちは')
1214+ * strio.each_char {|char| chars.push(char) }
1215+ * chars # => ["こ", "ん", "に", "ち", "は"]
1216+ *
1217+ * Stream position matters:
1218+ *
1219+ * chars = []
1220+ * strio = StringIO.new('こんにちは')
1221+ * strio.getc # => "こ"
1222+ * strio.pos # => 3 # 3-byte character was read.
1223+ * strio.each_char {|char| chars.push(char) }
1224+ * chars # => ["ん", "に", "ち", "は"]
1225+ *
1226+ * When at end-of-stream does not call the block:
1227+ *
1228+ * strio.eof? # => true
1229+ * strio.each_char {|char| fail 'Boo!' }
1230+ * strio.eof? # => true
1231+ *
1232+ * With no block given, returns a new {Enumerator}[https://docs.ruby-lang.org/en/master/Enumerator.html].
1233+ *
1234+ * Related: StringIO#each_byte, StringIO#each_codepoint, StringIO#each_line.
12031235 */
12041236static VALUE
12051237strio_each_char (VALUE self )
0 commit comments