Created
September 15, 2010 20:59
-
-
Save ryanbriones/581476 to your computer and use it in GitHub Desktop.
don't read too much into this...
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
module Procable | |
def to_proc | |
klazz = self | |
Proc.new { |*args| klazz.new(*args).run } | |
end | |
end | |
class MyIterator | |
extend Procable | |
def initialize(current_element, index_of_element) | |
@current_element = current_element | |
@index_of_element = index_of_element | |
end | |
def run | |
puts "current_element: #{@current_element}" | |
puts "index_of_element: #{@index_of_element}" | |
end | |
end | |
[1,2,3].each_with_index(&MyIterator) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment