Created
July 8, 2016 08:29
-
-
Save miyucy/10448870526cd1ca76a8c3ad1be6e839 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_support/core_ext/string/inflections' | |
require 'active_support/core_ext/hash/indifferent_access' | |
module Snaky | |
refine Hash do | |
def to_snake_case(value = self) | |
case value | |
when Hash | |
value.map { |k, v| [k.underscore, to_snake_case(v)] }.to_h.with_indifferent_access | |
when Array | |
value.map { |v| to_snake_case(v) } | |
else | |
value | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment