Feature: make capitalization optional in *humanize*

According to the documentation of ActiveSupport::Inflector:

humanize(lower_case_and_underscored_word)

Capitalizes the first word and turns underscores into spaces and strips a trailing “_id”, if any.

  • Example: humanize(“employee_salary”) # => “Employee salary”*

I would like to submit a pull request for humanize to accept a second optional parameter that would allow the string to be humanized without being capitalized.

humanize(lower_case_and_underscored_word, capitalize = true)

Turns underscores into spaces and strips a trailing “_id”, if any". Capitalizes the first word if capitalize=true

  • Example: humanize(“employee_salary”, false) # => “employee salary”*

I have stumbled into cases where I want to “humanize” a word without capitalizing it, and I’ve seen others occurring in the same problem.

What is your opinion about this? Thanks

Sounds good to me.

The documentation would say “if +capitalize+ is true”, with “true” in regular font. Please update the AS guide as well if you are so kind.

+1, I was just wishing for this last week :slight_smile:

Boolean arguments are really cryptic in most cases. Perhaps you should add an options hash instead?

E.g: humanize(“employee_salary”, capitalize: false)

Tomas Varneckas, I see your point!

Xavier Noria… do you agree as well? I think it reads better:

humanize(“employee_salary”) # => “Employee salary”

humanize(“employee_salary”, capitalize: false) # => “employee salary”

Tomas Varneckas, I see your point!

Xavier Noria… do you agree as well? I think it reads better:

humanize("employee_salary") # => "Employee salary"

humanize("employee_salary", capitalize: false) # => "employee salary"

Good!

Pull request sent! Add +capitalize+ option to Inflector.humanize by claudiob · Pull Request #12789 · rails/rails · GitHub