As an example, let’s say you want to create an index of ActiveRecord objects by their id. Use the Hash constructor that accepts an Array of key-value pairs and do it in one line:
posts_by_id = Hash[*Post.all.map{ |p| [p.id, p] }.flatten]
This tip was submitted by http://Fullware.net/.
You can use HTML tags for formatting. Wrap code in <code> tags and multiple lines of code in <pre><code> tags.