From f2489f493b794ee83a86e746b6240031acb8994e Mon Sep 17 00:00:00 2001 From: bogdanvlviv Date: Thu, 31 Mar 2016 02:11:19 +0300 Subject: Fix method String#upcase_first --- activesupport/lib/active_support/core_ext/string/inflections.rb | 4 +++- activesupport/lib/active_support/inflector/methods.rb | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/string/inflections.rb b/activesupport/lib/active_support/core_ext/string/inflections.rb index f301eeac43..7277f51076 100644 --- a/activesupport/lib/active_support/core_ext/string/inflections.rb +++ b/activesupport/lib/active_support/core_ext/string/inflections.rb @@ -224,7 +224,9 @@ class String # Converts just the first character to uppercase. # - # 'what a Lovely Day'.upcase_first # => "What a Lovely Day" + # 'what a Lovely Day'.upcase_first # => "What a Lovely Day" + # 'w'.upcase_first # => "W" + # ''.upcase_first # => "" def upcase_first ActiveSupport::Inflector.upcase_first(self) end diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index 3fbc19ddf8..f94e12e14f 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -142,9 +142,11 @@ module ActiveSupport # Converts just the first character to uppercase. # - # 'what a Lovely Day'.upcase_first # => "What a Lovely Day" + # upcase_first('what a Lovely Day') # => "What a Lovely Day" + # upcase_first('w') # => "W" + # upcase_first('') # => "" def upcase_first(string) - string[0].upcase.concat(string[1..-1]) + string.length > 0 ? string[0].upcase.concat(string[1..-1]) : '' end # Capitalizes all the words and replaces some characters in the string to -- cgit v1.2.3