instance method
humanize
Ruby on Rails edge
Since v3.0.20Signature
humanize(capitalize: true, keep_id_suffix: false)
Capitalizes the first word, turns underscores into spaces, and (by default) strips a
trailing '_id' if present.
Like `titleize`, this is meant for creating pretty output.
The capitalization of the first word can be turned off by setting the
optional parameter `capitalize` to false.
By default, this parameter is true.
The trailing '_id' can be kept by setting the
optional parameter `keep_id_suffix` to true.
By default, this parameter is false.
```
'employee_salary'.humanize # => "Employee salary"
'author_id'.humanize # => "Author"
'author_id'.humanize(capitalize: false) # => "author"
'_id'.humanize # => "Id"
'author_id'.humanize(keep_id_suffix: true) # => "Author id"
```
See ActiveSupport::Inflector.humanize.
: (?capitalize: boolish, ?keep_id_suffix: boolish) -> String
Parameters
-
capitalizekey = true -
keep_id_suffixkey = false
Source
# File activesupport/lib/active_support/core_ext/string/inflections.rb, line 306
def humanize(capitalize: true, keep_id_suffix: false)
ActiveSupport::Inflector.humanize(self, capitalize: capitalize, keep_id_suffix: keep_id_suffix)
end
Defined in activesupport/lib/active_support/core_ext/string/inflections.rb line 306
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in String