Ruby hashes are awesome! They allow us to efficiently access data by a key. A common task in data processing is to build hashes using Enumerable#each_with_object so we can quickly access related data during processing steps
In this example, we need to process a large amount of photo data by invoking process_photo, which needs a photo from our data and an instance from our Photographer model
Thanks to a recent addition to rubocop-rails, I learned that we can use Rails’ ActiveSupport method Enumerable#index_by to make this manipulation even easier
TLDR: use Enumerable#index_by over Enumerable#each_with_object
Are you ready to build something brilliant? We're ready to help.