Guest User

Untitled

a guest
Sep 25th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. class DictionaryPresenter
  2. include Enumerable
  3. def initialize(collection)
  4. @dictionary = ('A'..'Z').each_with_object({}){|l,h| h[l] = []}
  5. collection.each{|p| @dictionary[p.title[0]] << p}
  6. end
  7. def each &block
  8. @dictionary.each(&block)
  9. end
  10. end
  11. @posts = DictionaryPresenter.new(Post.all).as_dictionary
  12. # changed to this
  13. @posts = DictionaryPresenter.new(Post.all)
Add Comment
Please, Sign In to add comment