Created
November 2, 2015 20:13
-
-
Save cutalion/01d1af48cf19e6d42730 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Array | |
undef :each | |
def each | |
return to_enum(__callee__) unless block_given? | |
size.times do |i| | |
yield self[i] | |
end | |
end | |
end | |
arr = [1,2,3] | |
arr.each do |el| | |
p [:each, el] | |
end | |
enum = arr.each | |
p [:enum, enum.inspect] | |
p [:next, enum.next.inspect] | |
p [:next, enum.next.inspect] | |
p [:next, enum.next.inspect] | |
p [:next, enum.next.inspect] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment