Today I Learned
by OneCode

How to convert an array of objects into a hash?

Today I worked a lot on specs. I found something that might be useful also for you.

Here is a problem:

So, you know how to do this? Here is a solution:

array_of_objects = [ 'object1', object_value: true), 'object2', object_value: false), 'object3', object_value: true)
]{|item| [, item.object_value]}.to_h

#=> {"object1"=>true, "object2"=>false, "object3"=>true}