Adding first/last back onto OrderedHash

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

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

Just a side note... if you're wanting a default for the hash you could use the Hash#default= and Hash#default methods.