Accessible Hash is a simple wrapper around the built-in Ruby Hash that behaves
like a HashWithIndifferentAccess
and also allows object.attribute
style
access.
Manually:
gem install accessible-hash
or with Bundler (add to your Gemfile
):
gem 'accessible-hash'
require 'accessible-hash'
foo = AccessibleHash.new(bar: 'baz')
foo['bar'] # => 'baz'
foo[:bar] # => 'baz'
foo.bar # => 'baz'