Class: Hash

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

Instance Method Summary collapse

Instance Method Details

#camelize_keysObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/support/hash.rb', line 2

def camelize_keys
  input, output = self.dup, self.dup

  input.each do |key, _|
    case input[key]
      when String
        if key.to_s.include? '@'
          _key = ['@', key.to_s.gsub('@', '').camelize].join.to_sym
          output.delete(key)
          output[_key] = input[key]
        end
      when Hash
        output[key] = input[key].camelize_keys
      when Array
        output[key] = input.delete(key).map{ |item| item.camelize_keys }
    end
  end

  output
end