3 ms·
Is there a specific reason you chose to do arrays of arrays instead of hashes for subelements? I'd want the lists to come out as (maybe using a pluralizer or ma
by pi18n 16y ago
Is there a specific reason you chose to do arrays of arrays instead of hashes for subelements? I'd want the lists to come out as (maybe using a pluralizer or maybe not)
:items => [{:priority => :normal, :desc => '...'}, ...]
Then you could do more intuitive things like
todo_list.items.sort{|a,b| a[:priority] <=> b[:priority] }
which is somewhat stupid for symbols but not for numbers.
- ryan-allen 16y agoNo, no reason why I chose arrays, it's just a first cut. I was thinking of converting the representation for objects as the meaning of the three possible elements isn't explicit at the moment.
- alttab 16y agoOne thing to keep in mind is different Ruby implementations, versions, and platforms run differently. An array is currently the safest way to maintain order when it matters. If order didn't matter, than a hash would be fine, but iterating over the data could cause unwanted behavior if order is important and hash keys are served to an iterator in a different order than was laid out by the DSL code.