4 ms·
Other than recommending #map, #select, et al, the rest is poor advice. Consider the following recommendation input.inject({}) do |hash, item| hash.merge(
by jhawthorn 15y ago
Other than recommending #map, #select, et al, the rest is poor advice. Consider the following recommendation
input.inject({}) do |hash, item|
hash.merge(item => process(item))
end
Far, far slower, more memory intensive (big deal, given ruby's gc), and uglyer than the sane (and commonly accepted)
Hash[input.map do |item|
[item, process(item)]
end]