./lib/animoto/support/hash.rb in animoto-1.1.1 vs ./lib/animoto/support/hash.rb in animoto-1.2.0

- old
+ new

@@ -5,18 +5,18 @@ # Returns a new hash with only the listed keys from this hash. # # @param [Array<Object>] keys the keys to include # @return [Hash{Object=>Object}] a new hash with only the listed keys def only *keys - self.dup.delete_if { |k,v| !keys.include?(k) } + inject({}) { |h,(k,v)| h.merge(keys.include?(k) ? {k => v} : {}) } end unless {}.respond_to?(:only) # Returns a new hash with all keys from this hash except the listed ones. # # @param [Array<Object>] keys the keys to exclude # @return [Hash{Object=>Object}] a new hash without the listed keys def except *keys - self.dup.delete_if { |k,v| keys.include?(v) } + inject({}) { |h,(k,v)| h.merge(!keys.include?(v) ? {k => v} : {}) } end unless {}.respond_to?(:except) end end end \ No newline at end of file