Created
November 12, 2015 12:21
-
-
Save hugomaiavieira/da51bd1626624c394e12 to your computer and use it in GitHub Desktop.
Underscorize and Camelize
This file contains hidden or 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
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