Project

hash_ext

0.0
Low commit activity in last 3 years
No release in over a year
Hash extensions without monkey patching
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.8
~> 5.0, < 5.11
~> 0.2
~> 11.0
~> 0.14
 Project Readme

HashExt

Gem Version CI Coverage Status Code Climate

Hash extensions without monkey patching

Installation

Add this line to your application's Gemfile:

gem 'hash_ext'

And then execute:

$ bundle

Or install it yourself as:

$ gem install hash_ext

Usage

Accessible

hash = Hash::Accessible.new key_1: 1, key_2: { key_3: 3 }

hash[:key_1] # => 1
hash.key_1   # => 1

hash[:key_2] # => {key_3: 3}
hash.key_2   # => {key_3: 3}

hash[:key_2][:key_3] # => 3
hash.key_2.key_3     # => 3 

Builder

hash = Hash::Builder.build do |h|
  h.key_1 1
  h.key_2 do
    h.key_3 3
  end
end

hash # => {key_1: 1, key_2: {key_3: 3}}

Normalized

hash = Hash::Normalized.new { |key| key.upcase }

hash['key_1'] = 1

hash['key_1'] # => 1
hash['KEY_1'] # => 1

Indifferent

hash = Hash::Indifferent.new

hash['key_1'] = 1
hash[:key_2]  = 2

hash['key_1'] # => 1
hash[:key_1]  # => 1

hash['key_2'] # => 2
hash[:key_2]  # => 2

Sorted

hash = Hash::Sorted.asc { |k,v| k.to_s }

hash[:c] = 1
hash[:b] = 2
hash[:a] = 3

hash.keys # => [:a, :b, :c]

Nested

hash = Hash::Nested.new

hash[:level_1][:level_2][:level_3] = 'value'

hash # => {level_1: {level_2: {level_3: 'value'}}}

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/gabynaiman/hash_ext.

License

The gem is available as open source under the terms of the MIT License.