Just a side note... if you're wanting a default for the hash you could use the Hash#default= and Hash#default methods.
On Thu, Apr 9, 2009 at 2:41 AM, John Barton <[email protected]> wrote: > > > > On Apr 9, 3:07 pm, Jeremy Kemper <[email protected]> wrote: >> On Wed, Apr 8, 2009 at 8:39 PM, John Barton <[email protected]> wrote: >> > I just whipped up a tiny patch to add first and last back onto >> > OrderedHash (lost in the move from subclass of Array to subclass of >> > Hash) and hoped I could get some +1s / feedback. >> >> This was more an accident than a feature. How do you use it? >> >> jeremy > > Oh, just as shorthand: often to handle something like a default > cagegory. > > Code would often look something like this (contrived made-up example): > > @item_by_category = Post.all.group_by(&:category) > > @expanded_posts = params[:expanded] ? @item_by_category[params > [:expanded]] : @item_by_category.first > > I could have re-written our code but I've always liked the first/last > methods so I wrote the patch > > Cheers, > jb > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
