Created
April 4, 2016 16:30
-
-
Save youroff/f0200c24d8fe168455ee4a779064bce0 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
def transform(value, type = :unaltered) | |
case value | |
when Hash then value.deep_transform_keys! { |key| transform(key, type) } | |
when Symbol then transform(value.to_s, type).to_sym | |
when String | |
case type | |
when :dash then value.dasherize | |
when :camel then value.underscore.camelize | |
when :camel_lower then value.underscore.camelize(:lower) | |
when :underscore then value.underscore | |
else value | |
end | |
else value | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment