Class: Vermillion::Helper::Formatting

Inherits:
Object
  • Object
show all
Defined in:
lib/client/helper/formatting.rb

Instance Method Summary collapse

Instance Method Details

#symbolize(h) ⇒ Object

Recursively symbolize keys in a hash Params:

h

The hash you want to symbolize



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/client/helper/formatting.rb', line 7

def symbolize(h)
  case h
  when Hash
    Hash[
      h.map do |k, v|
        [k.respond_to?(:to_sym) ? k.to_sym : k, symbolize(v)]
      end
    ]
  when Enumerable
    h.map { |v| symbolize(v) }
  else
    h
  end
end