Skip to content

Instantly share code, notes, and snippets.

@workmad3
Created July 25, 2010 18:55
Show Gist options
  • Select an option

  • Save workmad3/489784 to your computer and use it in GitHub Desktop.

Select an option

Save workmad3/489784 to your computer and use it in GitHub Desktop.
module Enumerable
def inject_with_index(primer = nil)
each_with_index.inject(primer) do |acc, arr_with_idx|
yield acc, arr_with_idx[0], arr_with_idx[1]
end
end
end
[:a, :b, :c].inject_with_index({}) {|hsh, sym, idx| hsh.tap {|h| h[sym] = idx}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment