Created
May 1, 2009 19:00
-
-
Save chaserx/105189 to your computer and use it in GitHub Desktop.
This capitalize method doesn't bash hyphenated names
This file contains 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
#!/usr/local/bin/ruby -wKU | |
class String | |
def capitalize_with_hyphens! | |
if self.include? "-" | |
pieces_array = self.split("-") | |
pieces_array.each { |e| e.capitalize! } | |
joined = pieces_array.join("-") | |
replace(joined) | |
else | |
raise "Must contain at least one hyphen" | |
end | |
end | |
end | |
hyp_name = "zeta-jones" | |
puts hyp_name.capitalize_with_hyphens! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment