Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


translate value for 'has_key?' to Hash #253

wants to merge 1 commit into from

3 participants

Jamie Winsor Brian Donovan Yehuda Katz
Jamie Winsor

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

Brian Donovan

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.

Jamie Winsor

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.

Yehuda Katz

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

Jamie Winsor

@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
Commits on Sep 14, 2012
  1. Jamie Winsor
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 0 deletions.
  1. +4 −0 lib/thor/core_ext/hash_with_indifferent_access.rb
4 lib/thor/core_ext/hash_with_indifferent_access.rb
@@ -45,6 +45,10 @@ def merge!(other)
+ def has_key?(key)
+ super(convert_key(key))
+ end
def convert_key(key)
Something went wrong with that request. Please try again.