Skip to content

Instantly share code, notes, and snippets.

@BFalkner
Created May 21, 2010 21:04
Show Gist options
  • Save BFalkner/409429 to your computer and use it in GitHub Desktop.
Save BFalkner/409429 to your computer and use it in GitHub Desktop.
class Test
include Enumerable
def initialize(arr)
@arr = arr
end
def each(&block)
@arr.each do |el|
puts "start #{el}"
block.call(el)
puts "end #{el}"
end
end
end
> t = Test.new [0, 1, 1, 2, 3, 5]
=> #<Test:0x100348b80 @arr=[0, 1, 1, 2, 3, 5]>
> t.find {|n| n > 1}
start 0
end 0
start 1
end 1
start 1
end 1
start 2
=> 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment