I have an array of arrays (result of "pluck" usage) in following form:
arr = [[1, 'A1', 'B1'],[2, 'A2', 'B2'],[3, 'A3', 'B3']]
How to get following hash from it?
{1=>[1, 'A1', 'B1'], 2=>[2, 'A2', 'B2'], 3=>[3, 'A3', 'B3']}
I know this form, but surely there is one line form, too
hash = Hash.new
arr.each do |x|
hash[x[0]] = x
end
arr.each { |x| hash[x[0]] = x}arr.group_by(&:first)is more compact and more understandable.sa[0]in the value portion of theHash