Module: ActiveSupport::Inflector

Extended by:
Inflector
Included in:
Inflector
Defined in:
lib/titleize.rb

Instance Method Summary collapse

Instance Method Details

#titleize(title, opts = {}) ⇒ Object Also known as: titlecase

Capitalizes most words to create a nicer looking title string.

The list of “small words” which are not capped comes from the New York Times Manual of Style, plus 'vs' and 'v'.

This replaces the default Rails titleize. Like the default, it uses Inflector.underscore and Inflector.humanize to convert underscored_names and CamelCaseNames to a more human form. However, you can change this behavior by passing :humanize => false or :underscore => false as options. This can be useful when dealing with words like “iPod” and “GPS”.

titleize is also aliased as titlecase.

"notes on an active_record" # => "Notes on an Active Record"
"the GoodGerman"            # => "The Good German"

118
119
120
121
122
123
124
# File 'lib/titleize.rb', line 118

def titleize(title, opts={})
  opts = {:humanize => true, :underscore => true}.merge(opts)
  title = ActiveSupport::Inflector.underscore(title) if opts[:underscore]
  title = ActiveSupport::Inflector.humanize(title) if opts[:humanize]

  Titleize.titleize(title)
end