-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add titleize method to String. #9204
Conversation
Missing specs (you can take the examples in the method description). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides adding some specs, move it nearer the capitalize, upcase, downcase methods.
👍 |
It upcase all characters found after a space character.
Maybe this should preserve upper case characters? This would be useful for abbreviations. The current behaviour can be achieved with |
Preserve case makes sense to me, but I'm really not sure about what would be better. |
If you guys like the idea I can add tests to this PR.
This is similar
titleize
method Rails[1] add to Ruby strings, however with a difference:Rails replaces the
-
by spaces from words, but this doesn't work on all languages, e.g. in portuguese"fala-se muito"
should be"Fala-se Muito"
, not"Fala Se Muito"
as rails does.So this titleize just upcase letters after whitespaces, similar to already existing
capitalize
method.[1] https://apidock.com/rails/ActiveSupport/Inflector/titleize