Skip to content

Instantly share code, notes, and snippets.

@westdavidr
Last active May 25, 2016 13:18
Show Gist options
  • Save westdavidr/7c0a99551bdff6625e3c to your computer and use it in GitHub Desktop.
Save westdavidr/7c0a99551bdff6625e3c to your computer and use it in GitHub Desktop.
Nameize Ruby
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
@laurels69
Copy link

Ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment