Created
February 8, 2012 23:26
-
-
Save timuruski/1775382 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # As illustrated in http://confreaks.net/videos/427-rubyconf2010-zomg-why-is-this-code-so-slow | |
| Person = Struct.new(:name) | |
| people = [Person.new('steve'), Person.new('bill'), Person.new('larry')] | |
| puts people.inject({}) { |table,person| table[person.name] = person; table } | |
| puts Hash[people.map { |person| [person.name, person] }] | |
| # {"steve"=>#<struct Person name="steve">, "bill"=>#<struct Person name="bill">, "larry"=>#<struct Person name="larry">} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment