Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Initial caps with ruby on rails (See related posts)

class String
  # unicode_str.initial_caps => new_str
  # returns a copy of a string with initial capitals
  # "Jules-Édouard".initial_caps => "J.É."
  def initial_caps
    self.tr('-', ' ').split(' ').map { |word| word.chars.first.upcase.to_s + "." }.join
  end
end

You need to create an account or log in to post comments to this site.


Click here to browse all 4834 code snippets

Related Posts