Created
October 26, 2012 19:06
-
-
Save RoxasShadow/3960782 to your computer and use it in GitHub Desktop.
select_with_index
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 Enumerable | |
def select_with_index | |
i = 0 | |
self.select { |e| | |
i += 1 | |
yield e, i | |
} | |
end | |
end | |
ary = *(?a..?z) | |
len = ary.length | |
ary.select_with_index { |e, i| puts e if i == len / 2 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment