Skip to content

Instantly share code, notes, and snippets.

@ryanbriones
Created September 15, 2010 20:59
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 ryanbriones/581476 to your computer and use it in GitHub Desktop.
Save ryanbriones/581476 to your computer and use it in GitHub Desktop.
don't read too much into this...
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