Module: SnippetCli::HashUtils

Defined in:
lib/snippet_cli/hash_utils.rb

Overview

Shared hash-manipulation utilities used across validators.

Class Method Summary collapse

Class Method Details

.stringify_keys_deep(obj) ⇒ Object

Recursively converts symbol keys to string keys so the JSON schema validator can match property names. Symbol values are also stringified.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/snippet_cli/hash_utils.rb', line 8

def self.stringify_keys_deep(obj)
  case obj
  when Hash
    obj.each_with_object({}) { |(k, v), h| h[k.to_s] = stringify_keys_deep(v) }
  when Array
    obj.map { |item| stringify_keys_deep(item) }
  when Symbol
    obj.to_s
  else
    obj
  end
end