mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge pull request #4776 from shuujii/make-IO-each-family-without-block-to-return-Enumerator
Make `IO#each` family without block to return `Enumerator`
This commit is contained in:
@@ -303,6 +303,8 @@ class IO
|
||||
|
||||
# 15.2.20.5.3
|
||||
def each(&block)
|
||||
return to_enum unless block
|
||||
|
||||
while line = self.gets
|
||||
block.call(line)
|
||||
end
|
||||
@@ -311,6 +313,8 @@ class IO
|
||||
|
||||
# 15.2.20.5.4
|
||||
def each_byte(&block)
|
||||
return to_enum(:each_byte) unless block
|
||||
|
||||
while char = self.getc
|
||||
block.call(char)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user