Person = Struct.new(:id, :first_name, :last_name)a = [Person.new(1,'Alice', 'Smith'), Person.new(2, 'Bob', 'Smith'), Person.new(3,'Carol', 'Smith')]p m = a.group_by(&:id)
Standard input is empty
{1=>[#<struct Person id=1, first_name="Alice", last_name="Smith">], 2=>[#<struct Person id=2, first_name="Bob", last_name="Smith">], 3=>[#<struct Person id=3, first_name="Carol", last_name="Smith">]}
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!