The upcase method capitalizes the entire string, but I need to capitalize only the first letter.
Also, I need to support several popular languages, like German and Russian.
How do I do it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It depends on which Ruby version you use:
Ruby 2.4 and higher:
It just works, as since Ruby v2.4.0 supports Unicode case mapping:
Ruby 2.3 and lower:
The problem is, it just doesn’t do what you want it to, it outputs
марияinstead ofМария.If you’re using Rails there’s an easy workaround:
Otherwise, you’ll have to install the unicode gem and use it like this:
Ruby 1.8:
Be sure to use the coding magic comment:
gives
invalid multibyte char (US-ASCII), while:works without errors, but also see the “Ruby 2.3 and lower” section for real capitalization.