Method: ActiveSupport::Inflector#humanize
- Defined in:
- lib/jinx/active_support/inflector.rb
#humanize(lower_case_and_underscored_word) ⇒ Object
Capitalizes the first word and turns underscores into spaces and strips a trailing “_id”, if any. Like titleize, this is meant for creating pretty output.
Examples:
"employee_salary" #=>"Employee salary"
"author_id" #=>"Author"
230 231 232 233 234 235 |
# File 'lib/jinx/active_support/inflector.rb', line 230 def humanize(lower_case_and_underscored_word) result = lower_case_and_underscored_word.to_s.dup inflections.humans.each { |(rule, replacement)| break if result.gsub!(rule, replacement) } result.gsub(/_id$/, "").gsub(/_/, " ").capitalize end |