HashWithIndifferentAccess for keyword arguments
HashWithIndifferentAccess is a cool hash-like object that allows you to access values with either a symbol OR a string. But you can't pass it to a method that expects keyword arguments.
def foo(a:, b:); return a, b; end
h = HashWithIndifferentAccess.new({a: 1, b: 2})
foo(h)
=> ArgumentError: wrong number of arguments (1 for 0)
Fear not!
foo(h.symbolize_keys)
=> 1, 2
Calling symbolize_keys
on a HashWithIndifferentAccess object will create a hash that can be used for keyword arguments.
http://apidock.com/rails/v4.2.1/Hash/symbolize_keys
Tweet