4 ms·
Your general point about a one-line may be well made but your one-liner doesn't do what Steve's code does. Idiomatic or not, your dictionary will only have lett
by davnola 15y ago
Your general point about a one-line may be well made but your one-liner doesn't do what Steve's code does. Idiomatic or not, your dictionary will only have letters that correspond to posts' first letters.
The OP has the right idea but the wrong examples.
- tptacek 15y agoDid you read this: DictionaryPresenter.new(PostCategorizationPolicy, Post.all).as_dictionary Yeah, so that's getting a bit long. It happens. :) STEVE! LOOK OUT! BEES! So Steve wants an index by letter for posts. Building an index by letter for a collection in Ruby is practically a core function of the language. Generalize my comment above to, "don't wrap core functions of the language up in classes; do them in idiom".
- davnola 15y agoSure and I agree with your point about his example - it's not a good example. Did you read this: We've already added a new feature: any collection can now be displayed as a dictionary I think this a very weak motivation for creating a new class!
- tptacek 15y agoWhen you start writing ThreeCamelcaseWords for your class names, it's probably time start questioning the design. GoFites do this because they're Scared Of Code. Don't be afraid of code. Sure, don't poop it all over your files, cargo culting it from place to place. But also don't file it all away into a necronomicon to be conjured by name like a demon ("I Ankh-f-n-khonsu::Base, SET OVER THOSE THAT WOULD RENDER DICTIONARIES ORDERED BY FIRST LETTERS!").