collapsium
Provides various Hash extensions, and an UberHash class that uses them all.
Ruby's Hash is a pretty nice class, but various extensions are commonly (or not so commonly) used to make it even more convenient. The most notable would probably be ActiveSupport::HashWithIndifferentAccess.
That example, unfortunately, has all the problems of requring the kitchen sink that is ActiveSupport...
Functionality
- The
IndifferentAccessmodule provides support for indifferent access via a#default_proc:
x = { foo: 42 }
x.default_proc = ::Collapsium::IndifferentAccess::DEFAULT_PROC
x['foo'] # => 42
- The
RecursiveMergemodule provides a#recursive_mergefunction which merges Hashes recursively:
x = { foo: { bar: 42 } }
x.extend(::Collapsium::RecursiveMerge)
x.recursive_merge(foo: { baz: 'quux' })
# => {
# foo: {
# bar: 42,
# baz: 'quux',
# },
# }
- The
PathedAccessmodule provides a pathed access method to nested Hashes:
x = { "foo" => { "bar" => 42 } }
x.extend(::Collapsium::PathedAccess)
x["foo.bar"] # => 42
Finally, the UberHash class just includes all of the above.