Skip to content

Instantly share code, notes, and snippets.

@codeprimate
Created July 20, 2013 22:27
Show Gist options
  • Save codeprimate/6046661 to your computer and use it in GitHub Desktop.
Save codeprimate/6046661 to your computer and use it in GitHub Desktop.
def camel_case(txt)
txt.gsub(/(_*)([A-Za-z]+)(_*)/) { |m| $2.downcase.capitalize }
end
examples = [ "_foo_bar_quux_zurb_",
"foo_bar_quux",
"_foo_bar_quux",
"foo__bar-quux",
"_foo__bAr_qUUx" ]
examples.each do |text|
puts camel_case(text)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment