Created
January 1, 2011 20:31
-
-
Save fronx/761986 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| Enumerable.module_eval do | |
| def with_index | |
| index = -1 | |
| map { |item| [item, index += 1] } | |
| end | |
| end | |
| ['a','x','foo'].with_index.map { |a, index| a * index } | |
| # => ["", "x", "foofoo"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment