/ Published in: Ruby
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
# encoding: utf-8 ['one', 'two', 'three'] .each_with_index .inject({}) { |acc, (elm, i)| acc.merge Hash[i.succ, elm] } # {1 => 'one', 2 => 'two', 3 => 'three'}