group_by snippets

Grouping with group_by

Tagged group_by  Languages ruby
@groups = @products.group_by { |product| product.name.mb_chars[0].downcase.to_s }.sort

If you're using mb_chars, remember to call "to_s" or you won't get what you expect.