diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-04-28 21:30:46 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-04-28 21:37:05 +0900 |
| commit | cb55e7eca9b6e6bda7c238c4eec0984798ac11e9 (patch) | |
| tree | b85b5aac06ae179a5e50df38ea0088832b0076db | |
| parent | aff3743c129602d7757d2ffd690afcd42cc9cdc3 (diff) | |
| download | mruby-cb55e7eca9b6e6bda7c238c4eec0984798ac11e9.tar.gz mruby-cb55e7eca9b6e6bda7c238c4eec0984798ac11e9.zip | |
io.rb: reimplement `IO#each_char`.
It used to be an alias to `IO#each_byte` but those methods should have
behave differently.
| -rw-r--r-- | mrbgems/mruby-io/mrblib/io.rb | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/mrbgems/mruby-io/mrblib/io.rb b/mrbgems/mruby-io/mrblib/io.rb index 9ce49e51a..96797a47c 100644 --- a/mrbgems/mruby-io/mrblib/io.rb +++ b/mrbgems/mruby-io/mrblib/io.rb @@ -330,7 +330,7 @@ class IO def each_byte(&block) return to_enum(:each_byte) unless block - while char = self.getc + while char = self.getbyte block.call(char) end self @@ -339,7 +339,14 @@ class IO # 15.2.20.5.5 alias each_line each - alias each_char each_byte + def each_char(&block) + return to_enum(:each_byte) unless block + + while char = self.getc + block.call(char) + end + self + end def readlines ary = [] |
