Skip to content

Instantly share code, notes, and snippets.

@sintaxi
Created November 20, 2008 19:22
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 sintaxi/27148 to your computer and use it in GitHub Desktop.
Save sintaxi/27148 to your computer and use it in GitHub Desktop.
class String
def title_case!
self.split.map{ |w| w.capitalize }.join(' ')
end
end
class Hash
def title_case_keys!
self.each_pair do |k,v|
self[k.title_case!] = v
self.delete k
end
end
end
countries = {"UNITED STATES" => "USA" , "UNITED KINGDOM" => "UK"}.title_case_keys!
p countries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment