Skip to content

Instantly share code, notes, and snippets.

@automatthew
Created April 8, 2009 14:03
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 automatthew/91781 to your computer and use it in GitHub Desktop.
Save automatthew/91781 to your computer and use it in GitHub Desktop.
camel and snake casing
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