Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_admin/support/core_extensions.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.symbolize_hash(obj) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rails_admin/support/core_extensions.rb', line 6

def self.symbolize_hash(obj)
  case obj
  when Array
    obj.each_with_object([]) do |val, res|
      res << case val
             when Hash, Array then symbolize_hash(val)
             when String      then val.to_sym
             else val
             end
    end
  when Hash
    obj.each_with_object({}) do |(key, val), res|
      nkey = key.is_a?(String) ? key.to_sym : key
      nval = case val
             when Hash, Array then symbolize_hash(val)
             when String      then val.to_sym
             else val
             end
      res[nkey] = nval
    end
  else
    obj
  end
end

Instance Method Details

#symbolizeObject


2
3
4
# File 'lib/rails_admin/support/core_extensions.rb', line 2

def symbolize
  Hash.symbolize_hash(self)
end