hash_order_helper
Add methods to manipulate the order of the entries in the Hash object.
Installation
Add this line to your application's Gemfile:
gem 'hash_order_helper'
And then execute:
$ bundle
Or install it yourself as:
$ gem install hash_order_helper
Usage
require 'hash_order_helper'
hash = {b: 200, a: 100, c: 150}
hash.sort_pair
#=> {:a=>100, :b=>200, :c=>150}
hash.unshift(d: 300)
#=> {:d=>300, :b=>200, :a=>100, :c=>150}
The following methods are added:
sort_pair -> Hashsort_pair! -> Hashsort_pair_by {|key, value| ... } -> Hashsort_pair_by! {|key, value| ... } -> Hashat(nth) -> Arrayinsert(nth, hash) -> Hashlast -> Arraylast(n) -> Arraypop -> Arraypop(n) -> Arraypush(hash) -> Hashunshift(hash) -> Hash