Skip to content

Instantly share code, notes, and snippets.

@cutalion
Created November 2, 2015 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cutalion/01d1af48cf19e6d42730 to your computer and use it in GitHub Desktop.
Save cutalion/01d1af48cf19e6d42730 to your computer and use it in GitHub Desktop.
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