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...

Gem Version Build status Code Climate Test Coverage

Functionality

  • The IndifferentAccess module provides support for indifferent access via a #default_proc:
  x = { foo: 42 }
  x.default_proc = ::Collapsium::IndifferentAccess::DEFAULT_PROC
  x['foo'] # => 42
  • The RecursiveMerge module provides a #recursive_merge function which merges Hashes recursively:
  x = { foo: { bar: 42 } }
  x.extend(::Collapsium::RecursiveMerge)
  x.recursive_merge(foo: { baz: 'quux' })
  # => {
  #   foo: {
  #     bar: 42,
  #     baz: 'quux',
  #   },
  # }
  • The PathedAccess module 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.