Sha256: 01139f3174218861f5c3927d9bfb016bca759b46e76fb49c56783c8ede0e7b3f
Contents?: true
Size: 997 Bytes
Versions: 2
Compression:
Stored size: 997 Bytes
Contents
# HashFlatten Two methods i sometimes miss on Hash. ## `#destructure` hash = { a: 'a', b: { a: 'b' }, c: { b: { a: 'c' } } } hash.destructure => { 'a' => 'a', 'b.a' => 'b', 'c.b.a' => 'c' } ## `#structure` hash = { 'a' => 'a', 'b.a' => 'b', 'c.b.a' => 'c' } hash.structure => { 'a' => 'a', 'b' => { 'a' => 'b' }, 'c' => { 'b' => { 'a' => 'c' } } } ## Installation Add this line to your application's Gemfile: ```ruby gem 'hash_flatten' ``` And then execute: $ bundle Or install it yourself as: $ gem install hash_flatten ## Usage Use as refinement: ``` class MyClass using HashFlatten end ``` now you can call `#destructure` od `#structure` on hashes in `MyClass`. Here is an excellent blog post on refinements if you didn't use them before: http://interblah.net/why-is-nobody-using-refinements ## License The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
hash_flatten-0.3.0 | README.md |
hash_flatten-0.2.0 | README.md |