Created
April 8, 2009 14:03
-
-
Save automatthew/91781 to your computer and use it in GitHub Desktop.
camel and snake casing
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
def camel_case( string ) | |
string.split('_').map do |word| | |
"#{word.slice(/^\w/).upcase}#{word.slice(/^\w(\w+)/, 1)}" | |
end.join | |
end | |
def snake_case( string ) | |
string.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').downcase | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment