Skip to content

Instantly share code, notes, and snippets.

@hugomaiavieira
Created November 12, 2015 12:21
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 hugomaiavieira/da51bd1626624c394e12 to your computer and use it in GitHub Desktop.
Save hugomaiavieira/da51bd1626624c394e12 to your computer and use it in GitHub Desktop.
Underscorize and Camelize
class String
def camelize
gsub(/(?:_([a-z]))|(^[a-z])/){"#{($1||$2).upcase}"}
end
def undercorize
gsub(/(.)([A-Z])/,'\1_\2').downcase
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment