Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

translate value for 'has_key?' to Hash #253

Open
wants to merge 1 commit into from

3 participants

@reset

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

@eventualbuddha
Collaborator

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

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
Owner

@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

@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. @reset
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
View
4 lib/thor/core_ext/hash_with_indifferent_access.rb
@@ -45,6 +45,10 @@ def merge!(other)
self
end
+ def has_key?(key)
+ super(convert_key(key))
+ end
+
protected
def convert_key(key)
Something went wrong with that request. Please try again.