Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/laposta/utils/hash.rb

Instance Method Summary collapse

Instance Method Details

#permit(*filters) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/laposta/utils/hash.rb', line 2

def permit(*filters)
  res = {}
  filters.flatten.each do |filter|
    case filter
    when Symbol, String
      res[filter] = self[filter] if self.keys.include?(filter)
    when Hash then
      key = filter.keys.first
      res[key] = self[key].permit(filter[key]) if self.keys.include?(key)
    end
  end
  res
end