Skip to content

Instantly share code, notes, and snippets.

@appsol
Created May 25, 2014 10:18
Show Gist options
  • Save appsol/ca372d9ba1bbbf3996e4 to your computer and use it in GitHub Desktop.
Save appsol/ca372d9ba1bbbf3996e4 to your computer and use it in GitHub Desktop.
Saasbook Project 3.7
#!/usr/bin/env ruby
# Project 3.7
module Enumerable
def each_with_custom_index (start, step)
index = start
self.each do |x|
yield x, index
index+= step
end
end
end
%w(alice bob carol).each_with_index do |person,index|
puts ">> #{person} is number #{index}"
end
# >> alice is number 0
# >> bob is number 1
# >> carol is number 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment