Skip to content

Instantly share code, notes, and snippets.

@chaserx
Created May 1, 2009 19:00
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 chaserx/105189 to your computer and use it in GitHub Desktop.
Save chaserx/105189 to your computer and use it in GitHub Desktop.
This capitalize method doesn't bash hyphenated names
#!/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