Skip to content

translate value for 'has_key?' to Hash #253

Open
wants to merge 1 commit into from

3 participants

@reset
reset commented Sep 14, 2012

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

@eventualbuddha

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
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.

@wycats
Erikhuda member
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
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
Something went wrong with that request. Please try again.