Feature: make capitalization optional in *humanize*

151 views
Skip to first unread message

Claudio B.

unread,
Nov 6, 2013, 12:13:37 PM11/6/13
to rubyonra...@googlegroups.com
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




Xavier Noria

unread,
Nov 6, 2013, 12:45:57 PM11/6/13
to rubyonrails-core
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.

Chad Woolley

unread,
Nov 6, 2013, 12:57:08 PM11/6/13
to Ruby on Rails: Core
+1, I was just wishing for this last week :)


On Wed, Nov 6, 2013 at 10:45 AM, Xavier Noria <f...@hashref.com> wrote:
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.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/groups/opt_out.

Tomas Varneckas

unread,
Nov 6, 2013, 1:08:54 PM11/6/13
to rubyonra...@googlegroups.com
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.

unread,
Nov 6, 2013, 3:06:30 PM11/6/13
to rubyonra...@googlegroups.com
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"

Xavier Noria

unread,
Nov 6, 2013, 3:23:31 PM11/6/13
to rubyonrails-core
On Wed, Nov 6, 2013 at 9:06 PM, Claudio B. <clau...@gmail.com> wrote:
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.

unread,
Nov 6, 2013, 3:41:44 PM11/6/13
to rubyonra...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages