translate value for 'has_key?' to Hash #253

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
4 participants

reset commented Sep 14, 2012

this will translate the value of the 'has_key?' message to the parent of HashWithIndifferentAccess (Hash)

Contributor

eventualbuddha commented Sep 14, 2012

Was this a particular problem somewhere? Also, perhaps we should follow Rails' lead with this and implement key? and alias has_key?, include?, and member? to it.

https://github.com/rails/rails/blob/master/activesupport/lib/active_support/hash_with_indifferent_access.rb#L147-153

reset commented Sep 14, 2012

This is a particular problem if you pass an instance of HashWithIndifferentAccess to any function that calls has_key? with a symbol for it's parameter. This would go for any function on HashWithIndifferentAccess that interacts with keys via their identifier.

I use has_key? and am monkey patching this function in my project Berkshelf

It may be a good idea to add the remaining functions or a .to_hash function which accepts an argument to symbolize_keys.

Owner

wycats commented Feb 23, 2013

@reset I'm not comfortable with just doing this spot-fix. We should either support all of the hash methods or stick with the current set.

reset commented Feb 24, 2013

@wycats after using Thor for quite a bit more, I agree. Another option would be to use a pre-existing library which contains HashWithIndifferentAccess/Mashes like Hashie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment