Sha256: 7f57638e46365c4b98ff8d950fcc8e86d35cfab52e106051be8c910c7384f05d
Contents?: true
Size: 821 Bytes
Versions: 7
Compression:
Stored size: 821 Bytes
Contents
class Hash alias :original_delete :delete # support delete more than one keys # # original: delete(key) # current: delete(*keys) # # return [Hash] def delete *keys, &blk values = keys.each.with_object [] do |k,m| m << original_delete(k, &blk) end keys.length==1 ? values[0] : values end # confict with awesome_print which extend Array#grep # # grep pat at hash's keys, and return a new hash. # @see Array#grep # # @example # # foo = {a: 1, b: 2} # foo.grep(:a) #=> {a: 1} # # @return [Hash] #def grep(pat_s) # pats = Array===pat_s ? pat_s : [pat_s] # # filtered_keys = pats.each.with_object([]) { |pat, memo| # memo.push *self.keys.grep(pat) # } # filtered_keys.each.with_object({}) { |k,memo| # memo[k] = self[k] # } # end end # class Hash
Version data entries
7 entries across 7 versions & 1 rubygems