Sha256: d79e2ae47d96f03143d95efb91a9e6bc8ca5ecad6b71d53b5381443462329d99
Contents?: true
Size: 871 Bytes
Versions: 37
Compression:
Stored size: 871 Bytes
Contents
require 'set' require 'will_paginate/array' unless Hash.instance_methods.include? 'except' Hash.class_eval do # Returns a new hash without the given keys. def except(*keys) rejected = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys) reject { |key,| rejected.include?(key) } end # Replaces the hash without only the given keys. def except!(*keys) replace(except(*keys)) end end end unless Hash.instance_methods.include? 'slice' Hash.class_eval do # Returns a new hash with only the given keys. def slice(*keys) allowed = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys) reject { |key,| !allowed.include?(key) } end # Replaces the hash with only the given keys. def slice!(*keys) replace(slice(*keys)) end end end
Version data entries
37 entries across 37 versions & 20 rubygems