Sha256: 198ef51a7133c96235675e956f81031b078d042cd2e67d122eb42c419b7c110d
Contents?: true
Size: 625 Bytes
Versions: 2
Compression:
Stored size: 625 Bytes
Contents
# -*- encoding: utf-8 -*- # -*- frozen_string_literal: true -*- # -*- warn_indent: true -*- class Hash # Alters the hash by keeping only specified `keys` and returns it. # If the key is not present, returns empty `Hash`. # # ==== Arguments # # * +keys+ - +keys+ to be kept in the original `Hash`. # # ==== Examples # # {name: 'John', age: 30, occupation: 'Engineer', gender: 'Male'}.slice!(:name, :age) #=> {name: 'John', age: 30} # {name: 'John', age: 30, occupation: 'Engineer', gender: 'Male'}.slice!(:address) #=> {} def slice!(*keys) keep_if { |key, _| keys.include?(key) } end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rb_core_extensions-0.1.3 | lib/core_extensions/hash/delete.rb |
rb_core_extensions-0.1.2 | lib/core_extensions/hash/delete.rb |