Ruby – mapping an array to hashmap January 26, 2023 by Tarik Note that since Ruby 2.1.0 you can also use Array#to_h, like this: [1,2,3,4].map{ |x| [x, f(x)] }.to_h