No commit activity in last 3 years
No release in over 3 years
Add methods to manipulate the order of the entries in the Hash object.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
~> 3.0
 Project Readme

hash_order_helper

Add methods to manipulate the order of the entries in the Hash object.

Build Status

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 -> Hash
  • sort_pair! -> Hash
  • sort_pair_by {|key, value| ... } -> Hash
  • sort_pair_by! {|key, value| ... } -> Hash
  • at(nth) -> Array
  • insert(nth, hash) -> Hash
  • last -> Array
  • last(n) -> Array
  • pop -> Array
  • pop(n) -> Array
  • nd_push(hash) -> Hash non-destructive (alias: +)
  • push(hash) -> Hash (alias: <<)
  • nd_unshift(hash) -> Hash non-destructive
  • unshift(hash) -> Hash
  • >>(receiver_hash) -> Hash

>> method

require 'hash_order_helper'

hash = {b: 200, a: 100, c: 150}

{d: 300} >> hash
#=> {:d=>300, :b=>200, :a=>100, :c=>150}