Revision: 42084
Updated Code
at February 26, 2011 17:21 by Shamaoke
Updated Code
# 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'}
Revision: 42083
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at February 26, 2011 17:13 by Shamaoke
Initial Code
# encoding: utf-8
['one', 'two', 'three']
.each_with_index
.inject({}) { |acc, (elm, i)|
acc.merge({i.succ => elm})
}
# {1 => 'one', 2 => 'two', 3 => 'three'}
Initial URL
Initial Description
Initial Title
inject with index
Initial Tags
ruby
Initial Language
Ruby