README.md in hash_ext-0.1.1 vs README.md in hash_ext-0.2.0

- old
+ new

@@ -1,12 +1,12 @@ # HashExt -[![Gem Version](https://badge.fury.io/rb/hash_ext.png)](https://rubygems.org/gems/hash_ext) -[![Build Status](https://travis-ci.org/gabynaiman/hash_ext.png?branch=master)](https://travis-ci.org/gabynaiman/hash_ext) -[![Coverage Status](https://coveralls.io/repos/gabynaiman/hash_ext/badge.png?branch=master)](https://coveralls.io/r/gabynaiman/hash_ext?branch=master) -[![Code Climate](https://codeclimate.com/github/gabynaiman/hash_ext.png)](https://codeclimate.com/github/gabynaiman/hash_ext) -[![Dependency Status](https://gemnasium.com/gabynaiman/hash_ext.png)](https://gemnasium.com/gabynaiman/hash_ext) +[![Gem Version](https://badge.fury.io/rb/hash_ext.svg)](https://rubygems.org/gems/hash_ext) +[![Build Status](https://travis-ci.org/gabynaiman/hash_ext.svg?branch=master)](https://travis-ci.org/gabynaiman/hash_ext) +[![Coverage Status](https://coveralls.io/repos/gabynaiman/hash_ext/badge.svg?branch=master)](https://coveralls.io/r/gabynaiman/hash_ext?branch=master) +[![Code Climate](https://codeclimate.com/github/gabynaiman/hash_ext.svg)](https://codeclimate.com/github/gabynaiman/hash_ext) +[![Dependency Status](https://gemnasium.com/gabynaiman/hash_ext.svg)](https://gemnasium.com/gabynaiman/hash_ext) Hash extensions without monkey patching ## Installation @@ -24,16 +24,73 @@ $ gem install hash_ext ## Usage -### Available classes +### Accessible ```ruby -Hash::Accessible -Hash::Builder -Hash::Indifferent -Hash::Sorted +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 + +```ruby +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 + +```ruby +hash = Hash::Normalized.new { |key| key.upcase } + +hash['key_1'] = 1 + +hash['key_1'] # => 1 +hash['KEY_1'] # => 1 +``` + +### Indifferent + +```ruby +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 + +```ruby +hash = Hash::Sorted.asc { |k,v| k.to_s } + +hash[:c] = 1 +hash[:b] = 2 +hash[:a] = 3 + +hash.keys # => [:a, :b, :c] ``` ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.