Convert array of hashes to array of structs?
- by keruilin
Let's say I have two objects: User and Race. User has two attributes: first_name, last_name. And Race has three attributes: course, start_time, end_time.
Now let's say I create an array of hashes like this:
user_races = races.map{ |race| {:user = race.user, :race = race} }
How do I then convert user_races into an array of structs, keeping in mind that I want to be able to access the attributes of both user and race from the struct element?