Today I Learned

hashrocket A Hashrocket project

ActiveSupport Inflections - humanize vs titleize

ActiveSupport has a lot of useful inflections to transform strings, and I often forget which one does what exactly.

#humanize will capitalize the first word, whereas #titleize will capitalize every word:

"hi_how_are_you?".humanize
# => "Hi how are you?"

"hi_how_are_you?".titleize
# => "Hi How Are You?"

Actually, it turns out #titleize is just a special case of #humanize!

See More #rails TILs
Looking for help? Hashrocket has been an industry leader in Ruby on Rails since 2008. Rails is a core skill for each developer at Hashrocket, and we'd love to take a look at your project. Contact us and find out how we can help you.