Created
May 25, 2014 10:18
-
-
Save appsol/ca372d9ba1bbbf3996e4 to your computer and use it in GitHub Desktop.
Saasbook Project 3.7
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
#!/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