Sha256: 3f57a0f4fa309f50d862c05c89c2e080c73edafc85b6a5beef139613fbe4a31b
Contents?: true
Size: 818 Bytes
Versions: 27
Compression:
Stored size: 818 Bytes
Contents
module CoreExt module Hash def pick(*picks) picks = picks.flatten mapped_picks = {} picks.each do |pick| if pick.is_a?(Hash) mapped_picks.merge!(pick) else mapped_picks[pick] = pick end end mapped_picks.inject({}) do |result, (key, new_key)| result[new_key] = self[key] if self.key?(key) result end end def pick!(*picks) picks = picks.flatten keys.each {|key| self.delete(key) unless picks.member?(key) } end def except(*picks) result = self.dup result.except!(*picks) result end def except!(*picks) picks = picks.flatten keys.each {|key| self.delete(key) if picks.member?(key) } end end end Hash.send :include, CoreExt::Hash
Version data entries
27 entries across 27 versions & 1 rubygems