class Hash
Public Instance Methods
to_snake_keys(value = self)
click to toggle source
sourced from: github.com/futurechimp/plissken/blob/master/lib/plissken/ext/hash/to_snake_keys.rb
# File lib/gclouder/monkey_patches/hash.rb, line 5 def to_snake_keys(value = self) case value when Array value.map { |v| to_snake_keys(v) } when Hash snake_hash(value) else value end end
Private Instance Methods
snake_hash(value)
click to toggle source
# File lib/gclouder/monkey_patches/hash.rb, line 18 def snake_hash(value) Hash[value.map { |k, v| [underscore_key(k), to_snake_keys(v)] }] end
underscore(string)
click to toggle source
# File lib/gclouder/monkey_patches/hash.rb, line 32 def underscore(string) string.gsub(/::/, '/') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr('-', '_') .downcase end
underscore_key(k)
click to toggle source
# File lib/gclouder/monkey_patches/hash.rb, line 22 def underscore_key(k) if k.is_a? Symbol underscore(k.to_s) elsif k.is_a? String underscore(k) else k end end