Skip to content

Instantly share code, notes, and snippets.

@youroff
Created April 4, 2016 16:30
Show Gist options
  • Save youroff/f0200c24d8fe168455ee4a779064bce0 to your computer and use it in GitHub Desktop.
Save youroff/f0200c24d8fe168455ee4a779064bce0 to your computer and use it in GitHub Desktop.
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