instance method
humanize
Ruby on Rails 3.2.22.5
Since v2.2.3Signature
humanize(lower_case_and_underscored_word)
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"
Parameters
-
lower_case_and_underscored_wordreq
Source
# File activesupport/lib/active_support/inflector/methods.rb, line 94
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$/, "")
result.gsub!(/_/, ' ')
result.gsub(/([a-z\d]*)/i) { |match|
"#{inflections.acronyms[match] || match.downcase}"
}.gsub(/^\w/) { $&.upcase }
end
Defined in activesupport/lib/active_support/inflector/methods.rb line 94
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveSupport::Inflector