Created
May 22, 2013 14:06
-
-
Save mguterl/5627778 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Enumerator | |
def end? | |
peek | |
false | |
rescue StopIteration | |
true | |
end | |
end | |
enum = Enumerator.new { |yielder| yielder.yield 1; yielder.yield 2 } | |
enum.end? # => false | |
enum.next # => 1 | |
enum.end? # => false | |
enum.next # => 2 | |
enum.end? # => true | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment