Today I Learned

** operator as a way to merge hashes && symbolize_keys

array.group_by(&:something).map do |scheduled_at, form_submissions|
  { scheduled_at: scheduled_at, **form_submissions.first.payload.symbolize_keys }
end

What’s happening here?

The double splat operator acts as a handy way to merge two hashes. But since the payload contains a json with keys being strings, it will throw an exception of TypeError: hash key "name" is not a Symbol

This is because of the Ruby’s implementation internal detail: The keyword arguments, which the double-splat operator is supposed to capture, are expressed in Ruby as Symbols. Hence, the symbolize_keys call.