Rails 6 ActiveSupport::HashWithIndifferentAccess fix
Rails 6 fixes without (alias of slice) method on ActiveSupport::HashWithIndifferent for sybmol arguments.
ActiveSupport::HashWithIndifferentAccess#except
is aliased to without
method.
When symbol argument was sent to without
method
on
ActiveSupport::HashWithIndifferent
object,
it used to return the same object.
It did not consider symbol arguments
to perform without
operation.
Let’s take an example to demonstrate the use case.
Before Rails 6
Now, if we want to fetch a new hash
without key value pair having key a
.
As we can see from the result above,
the resultant hash has the key passed as a symbol argument to without
method.
Whereas it works if we pass string argument as given below.
After Rails 6
Rails 6 has fixed the bug describe above.
Now,
if we try to perform the same operation,
it gives the expected result with a hash
having key-value pair having key a
omitted
from the result.
It also works with string argument to without
method
on ActiveSupport::HashWithIndifferentAccess.
All this works as shows above with except
method as well.
Reference
- Pull Request: Fix HashWithIndifferentAccess#without bug
- Hash#except method
Subscribe to Ruby in Rails
Get the latest posts delivered right to your inbox