Hash with multiple keys for same value, symbol/string-indifferent key access.
Add this line to your application's Gemfile:
gem 'multi_key_hash'
And then execute:
$ bundle
Or install it yourself as:
$ gem install multi_key_hash
require 'multi_key_hash'
multi_hash = MultiKeyHash.new({%w[one two three] => 'number', %i[a b c] => 'letter', 'single' => 'value'})
multi_hash['one'] # number
multi_hash[:a] # letter
multi_hash['single'] # value
multi_hash = MultiKeyHash.new({%w[one two three] => 'number', %i[a b c] => 'letter', 'single' => 'value'})
multi_hash['one'] = 'first_number' # first_number
multi_hash['two'] # number
multi_hash[:a] = 'first_letter' # first_letter
multi_hash[:b] # letter
multi_hash = MultiKeyHash.new({%w[one two three] => 'number', %i[a b c] => 'letter', 'single' => 'value'})
multi_hash[:language] = 'english' # single key
multi_hash[[:ruby, :js, :php]] = 'programming_language' # multiple keys
multi_hash = MultiKeyHash.new({%w[one two three] => 'number', %i[a b c] => 'letter', 'single' => 'value'})
multi_hash.delete(:a)
multi_hash[:b] #letter
multi_hash.delete('one')
multi_hash['two'] #number
multi_hash = MultiKeyHash.new({%w[one two three] => 'number', %i[a b c] => 'letter', 'single' => 'value'})
multi_hash.to_h
# {
# 'one' => 'number',
# 'two' => 'number',
# 'three' => 'number',
# :a => 'letter',
# :b => 'letter',
# :c => 'letter',
# 'single' => 'value'
# }