Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

String#titleize works properly with smart quotes, closes #5584

  • Loading branch information...
commit 633ee64e20da05ddbcab67558351733ba511a444 1 parent 1d59caa
@nashby nashby authored
View
6 activesupport/lib/active_support/inflector/methods.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
require 'active_support/inflector/inflections'
module ActiveSupport
@@ -112,7 +114,7 @@ def humanize(lower_case_and_underscored_word)
# "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 }
+ humanize(underscore(word)).gsub(/\b(['’`]?[a-z])/) { $1.capitalize }
end
# Create the name of a table like Rails does for models to table names. This method
@@ -209,7 +211,7 @@ def foreign_key(class_name, separate_class_name_and_id_with_underscore = true)
def constantize(camel_cased_word) #:nodoc:
names = camel_cased_word.split('::')
names.shift if names.empty? || names.first.empty?
-
+
names.inject(Object) do |constant, name|
constant.const_get(name, false)
end
View
4 activesupport/test/inflector_test_cases.rb
@@ -220,7 +220,9 @@ module InflectorTestCases
'Actionwebservice' => 'Actionwebservice',
"david's code" => "David's Code",
"David's code" => "David's Code",
- "david's Code" => "David's Code"
+ "david's Code" => "David's Code",
+ "Fred’s" => "Fred’s",
+ "Fred`s" => "Fred`s"
}
OrdinalNumbers = {
Please sign in to comment.
Something went wrong with that request. Please try again.