Module: Relaton::Render::Utils

Defined in:
lib/relaton/render/utils/utils.rb

Class Method Summary collapse

Class Method Details

.string_keys(hash) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/relaton/render/utils/utils.rb', line 4

def self.string_keys(hash)
  case hash
  when Hash
    hash.each_with_object({}) do |(k, v), ret|
      ret[k.to_s] = string_keys(v)
    end
  when Array then hash.map { |n| string_keys(n) }
  else hash
  end
end

.sym_keys(hash) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/relaton/render/utils/utils.rb', line 15

def self.sym_keys(hash)
  case hash
  when Hash
    hash.each_with_object({}) do |(k, v), ret|
      ret[k.to_sym] = sym_keys(v)
    end
  when Array then hash.map { |n| sym_keys(n) }
  else hash
  end
end