module GorillaPatch::Slice
Adding slice methods
Public Instance Methods
slice(*keys, nils: false)
click to toggle source
Calls superclass method
# File lib/gorilla_patch/slice.rb, line 7 def slice(*keys, nils: false) return super if defined?(super) && !nils keys.each_with_object(self.class.new) do |k, hash| hash[k] = self[k] if nils || key?(k) end end
slice!(*keys, nils: false)
click to toggle source
# File lib/gorilla_patch/slice.rb, line 15 def slice!(*keys, nils: false) omit = slice(*self.keys - keys, nils: nils) hash = slice(*keys, nils: nils) replace(hash) omit end
slice_reverse!(*keys, nils: false)
click to toggle source
# File lib/gorilla_patch/slice.rb, line 22 def slice_reverse!(*keys, nils: false) omit = slice!(*keys, nils: nils) hash = dup replace(omit) hash end