Changeset 2690
- Timestamp:
- 10/19/05 20:20:11 (3 years ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (2 diffs)
- trunk/activesupport/lib/active_support/core_ext/string/inflections.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/inflector.rb (modified) (1 diff)
- trunk/activesupport/test/inflector_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r2687 r2690 1 * Add title case method to String to do, e.g., 'action_web_service'.titlecase # => 'Action Web Service'. [Marcel Molina Jr.] 2 1 3 *1.2.1* (October 19th, 2005) 2 4 … … 4 6 5 7 * Show all framework frames in the framework trace. [Nicholas Seckar] 6 7 8 8 9 *1.2.0* (October 16th, 2005) trunk/activesupport/lib/active_support/core_ext/string/inflections.rb
r1854 r2690 16 16 Inflector.camelize(self) 17 17 end 18 alias_method :camelcase, :camelize 19 20 def titleize 21 Inflector.titleize(self) 22 end 23 alias_method :titlecase, :titleize 18 24 19 25 def underscore trunk/activesupport/lib/active_support/inflector.rb
r2227 r2690 113 113 lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase } 114 114 end 115 116 def titleize(word) 117 humanize(underscore(word)).gsub(/\b([a-z])/) { $1.capitalize } 118 end 115 119 116 120 def underscore(camel_cased_word) trunk/activesupport/test/inflector_test.rb
r2227 r2690 145 145 "employee_id" => "Employee", 146 146 "underground" => "Underground" 147 } 148 149 MixtureToTitleCase = { 150 'active_record' => 'Active Record', 151 'ActiveRecord' => 'Active Record', 152 'action web service' => 'Action Web Service', 153 'Action Web Service' => 'Action Web Service', 154 'Action web service' => 'Action Web Service', 155 'actionwebservice' => 'Actionwebservice', 156 'Actionwebservice' => 'Actionwebservice' 147 157 } 148 158 … … 197 207 end 198 208 209 MixtureToTitleCase.each do |before, title_cased| 210 define_method 'test_titlecase' do 211 assert_equal(title_cased, Inflector.titleize(before)) 212 end 213 end 214 199 215 def test_camelize 200 216 CamelToUnderscore.each do |camel, underscore|