Hey guys, 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. https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2463-add-first-and-last-to-orderedhash 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
On Wed, Apr 8, 2009 at 8:39 PM, John Barton <jrbarton@gmail.com> 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 --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
On Apr 9, 3:07 pm, Jeremy Kemper <jer...@bitsweat.net> wrote:> On Wed, Apr 8, 2009 at 8:39 PM, John Barton <jrbar...@gmail.com> 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? > > jeremyOh, 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
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 <jrbarton@gmail.com> wrote:> > > > On Apr 9, 3:07 pm, Jeremy Kemper <jer...@bitsweat.net> wrote: >> On Wed, Apr 8, 2009 at 8:39 PM, John Barton <jrbar...@gmail.com> 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---