Claudio_B
(Claudio B.)
November 6, 2013, 5:13pm
1
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
fxn
(Xavier Noria)
November 6, 2013, 5:45pm
2
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
Boolean arguments are really cryptic in most cases.
Perhaps you should add an options hash instead?
E.g:
humanize(“employee_salary”, capitalize: false)
Claudio_B
(Claudio B.)
November 6, 2013, 8:06pm
5
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”
fxn
(Xavier Noria)
November 6, 2013, 8:23pm
6
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!
Claudio_B
(Claudio B.)
November 6, 2013, 8:41pm
7