Skip to content

Commit

Permalink
search private and protected methods for convert_key
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Mar 20, 2012
1 parent 440559f commit c317c5b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions activesupport/lib/active_support/core_ext/hash/slice.rb
Expand Up @@ -13,15 +13,15 @@ class Hash
# valid_keys = [:mass, :velocity, :time]
# search(options.slice(*valid_keys))
def slice(*keys)
keys.map! { |key| convert_key(key) } if respond_to?(:convert_key)
keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true)
keys.each_with_object(self.class.new) { |k, hash| hash[k] = self[k] if has_key?(k) }
end

# Replaces the hash with only the given keys.
# Returns a hash contained the removed key/value pairs
# {:a => 1, :b => 2, :c => 3, :d => 4}.slice!(:a, :b) # => {:c => 3, :d => 4}
def slice!(*keys)
keys.map! { |key| convert_key(key) } if respond_to?(:convert_key)
keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true)
omit = slice(*self.keys - keys)
hash = slice(*keys)
replace(hash)
Expand Down
Expand Up @@ -5,7 +5,7 @@ module ActiveSupport
# people can write <tt>params[:key]</tt> instead of <tt>params['key']</tt>
# and they get the same value for both keys.
class HashWithIndifferentAccess < Hash

# Always returns true, so that <tt>Array#extract_options!</tt> finds members of this class.
def extractable_options?
true
Expand Down

0 comments on commit c317c5b

Please sign in to comment.