require'active_support/hash_with_indifferent_access'require'minitest/autorun'defsum(a: 0,b: 0)a+bendclassBugTest<MiniTest::Unit::TestCasedefsetup@normal_hash={a: 18,b: 24}# just a hash@indiff_hash=ActiveSupport::HashWithIndifferentAccess.new(@normal_hash)enddeftest_ruby_hashassert_equal42,sum(@normal_hash)enddeftest_hash_with_indifferent_accessassert_equal42,sum(@indiff_hash)endend
Just to be clear this issue is not about HashWithIndifferentAccess, it is about using hash with string keys to be used as keyword arguments (HashWithIndifferentAccess store the keys as strings).
I am negative for the proposal. My opinion is that you should not (or no longer) use strings as keywords.
For transition purpose, ActiveSupport (or something else) can add a method to convert strings keys to symbol keys.
Yes, I agree with you. I'm also not positive to changing keyword arguments to receive even strings and symbols, but I thought OP should request this feature here since it is not Rails specific, as he would have the same behavior with a normal hash using string keys.
As soon we only support Ruby 2.2 we can store the keywords as symbols, but until there, we can't change HashWithIndifferentAccess to use symbols or we are opening Rails applications to receive DDoS attacks.
We already have this method to convert strings keys to symbol keys. It is called symbolize_keys. And in my opinion it is fine to use if you know what is doing. I would never call symbolize_keys in request parameters for example. At least not until my application is running with the new symbol GC.
I agree with the above comments. Probably waiting for Ruby 2.2 would be the best course of action here.
I will try nevertheless create a workaround by utilising Method#parameters to feed the usual params.slice(*args).symbolize_keys in a clever and unobstructive way. Hints/ideas are welcome.