Skip to content
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

Merged
merged 1 commit into from
May 4, 2020
Merged

Conversation

hugopl
Copy link
Contributor

@hugopl hugopl commented Apr 29, 2020

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

@j8r
Copy link
Contributor

j8r commented Apr 29, 2020

Missing specs (you can take the examples in the method description).

Copy link
Member

@bcardiff bcardiff left a 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.

@hugopl
Copy link
Contributor Author

hugopl commented Apr 30, 2020

Besides adding some specs, move it nearer the capitalize, upcase, downcase methods.

👍

It upcase all characters found after a space character.
@straight-shoota
Copy link
Member

Maybe this should preserve upper case characters? This would be useful for abbreviations. The current behaviour can be achieved with downcase.titelize.

@hugopl
Copy link
Contributor Author

hugopl commented Apr 30, 2020

Maybe this should preserve upper case characters? This would be useful for abbreviations. The current behaviour can be achieved with downcase.titelize.

Preserve case makes sense to me, but I'm really not sure about what would be better. capitalize don't do this and downcase everything but first letter. I would like to listen what other reviewers think about it.

@hugopl hugopl requested a review from bcardiff April 30, 2020 17:39
@hugopl hugopl changed the title RFC: Add titleize method to String. Add titleize method to String. Apr 30, 2020
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants