Convert array of hashes to array of structs?

Posted by keruilin on Stack Overflow See other posts from Stack Overflow or by keruilin
Published on 2010-03-24T02:09:39Z Indexed on 2010/03/24 2:13 UTC
Read the original article Hit count: 389

Filed under:
|
|
|
|

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?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about struct