Rails tip: Titleize acronyms

I ran into a problem whilst trying to titleize a string containing an acronym. For example:

  "building an API".titleize

Will output

  Building An Api

Not exactly what I was after but with a small change to the Inflector class you can define your own acronyms.


ActiveSupport::Inflector.inflections do |inflect|
  inflect.acronym "API"


  "Building An API".titleize
Written on October 9, 2013