Skip to content

Instantly share code, notes, and snippets.

@fronx
Created January 1, 2011 20:31
Show Gist options
  • Select an option

  • Save fronx/761986 to your computer and use it in GitHub Desktop.

Select an option

Save fronx/761986 to your computer and use it in GitHub Desktop.
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