Skip to content

Instantly share code, notes, and snippets.

@miyucy
Created July 8, 2016 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miyucy/10448870526cd1ca76a8c3ad1be6e839 to your computer and use it in GitHub Desktop.
Save miyucy/10448870526cd1ca76a8c3ad1be6e839 to your computer and use it in GitHub Desktop.
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