Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Additional examples for #titleize in ActiveSupport #2019

Closed
wants to merge 1 commit into from

2 participants

@pol
pol commented

There weren't examples for the behavior of #titleize on camelcased or underscored strings.

@josevalim
Owner

Please push documentation changes straight to github.com/lifo/docrails . it is an open repo! thanks!

@josevalim josevalim closed this
@pol
pol commented

Will do, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 8, 2011
  1. @pol
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 2 deletions.
  1. +4 −2 activesupport/lib/active_support/inflector/methods.rb
View
6 activesupport/lib/active_support/inflector/methods.rb
@@ -118,8 +118,10 @@ def humanize(lower_case_and_underscored_word)
# +titleize+ is also aliased as as +titlecase+.
#
# Examples:
- # "man from the boondocks".titleize # => "Man From The Boondocks"
- # "x-men: the last stand".titleize # => "X Men: The Last Stand"
+ # "man from the boondocks".titleize # => "Man From The Boondocks"
+ # "x-men: the last stand".titleize # => "X Men: The Last Stand"
+ # "TheManWithoutAPast".titleize # => "The Man Without A Past"
+ # "raiders_of_the_lost_ark".titleize # => "Raiders Of The Lost Ark"
def titleize(word)
humanize(underscore(word)).gsub(/\b('?[a-z])/) { $1.capitalize }
end
Something went wrong with that request. Please try again.