Last active
May 25, 2016 13:18
-
-
Save westdavidr/7c0a99551bdff6625e3c to your computer and use it in GitHub Desktop.
Nameize Ruby
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 | |
SPACE = ' ' | |
APOS = "'" | |
def nameize | |
case self | |
when / / | |
downcase.split(SPACE).each { |part| part.nameize! }.join(SPACE) | |
when /^(mac|mc)(\w)(.*)$/i | |
"#{$1.capitalize}#{$2.capitalize}#{$3}" | |
when /\'/ | |
downcase.split(APOS).each{ |piece| piece.capitalize! }.join(APOS) | |
else | |
downcase.capitalize | |
end | |
end | |
def nameize! | |
replace nameize | |
end | |
end | |
puts "COLYN O'REILLY".nameize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ok