aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2016-03-30 01:08:33 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2016-03-30 01:08:33 -0300
commit3be1a75f3fff1042934ba60ae4093237a6b31712 (patch)
tree0f341af38f85d33e20cf6163a13962d5fc02a264 /activesupport
parent0df82a64530ee208fc2a7d1b19af75a39c1a44a0 (diff)
parent7047e5562118d23c66c390b004f74ed35b90ab14 (diff)
downloadrails-3be1a75f3fff1042934ba60ae4093237a6b31712.tar.gz
rails-3be1a75f3fff1042934ba60ae4093237a6b31712.tar.bz2
rails-3be1a75f3fff1042934ba60ae4093237a6b31712.zip
Merge pull request #23895 from glaucocustodio/add_upcase_first_method
Add upcase_first method
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG.md4
-rw-r--r--activesupport/lib/active_support/core_ext/string/inflections.rb7
-rw-r--r--activesupport/lib/active_support/inflector/methods.rb7
-rw-r--r--activesupport/test/core_ext/string_ext_test.rb4
4 files changed, 22 insertions, 0 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index b9dcbe53c1..dd1b347e73 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Add `String#upcase_first` method.
+
+ *Glauco Custódio*
+
* Prevent `Marshal.load` from looping infinitely when trying to autoload a constant
which resolves to a different name.
diff --git a/activesupport/lib/active_support/core_ext/string/inflections.rb b/activesupport/lib/active_support/core_ext/string/inflections.rb
index cc71b8155d..f301eeac43 100644
--- a/activesupport/lib/active_support/core_ext/string/inflections.rb
+++ b/activesupport/lib/active_support/core_ext/string/inflections.rb
@@ -222,6 +222,13 @@ class String
ActiveSupport::Inflector.humanize(self, options)
end
+ # Converts just the first character to uppercase.
+ #
+ # 'what a Lovely Day'.upcase_first # => "What a Lovely Day"
+ def upcase_first
+ ActiveSupport::Inflector.upcase_first(self)
+ end
+
# Creates a foreign key name from a class name.
# +separate_class_name_and_id_with_underscore+ sets whether
# the method should put '_' between the name and 'id'.
diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb
index f741c0bfb8..3fbc19ddf8 100644
--- a/activesupport/lib/active_support/inflector/methods.rb
+++ b/activesupport/lib/active_support/inflector/methods.rb
@@ -140,6 +140,13 @@ module ActiveSupport
result
end
+ # Converts just the first character to uppercase.
+ #
+ # 'what a Lovely Day'.upcase_first # => "What a Lovely Day"
+ def upcase_first(string)
+ string[0].upcase.concat(string[1..-1])
+ end
+
# Capitalizes all the words and replaces some characters in the string to
# create a nicer looking title. +titleize+ is meant for creating pretty
# output. It is not used in the Rails internals.
diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb
index 2e69816364..5c0b60039a 100644
--- a/activesupport/test/core_ext/string_ext_test.rb
+++ b/activesupport/test/core_ext/string_ext_test.rb
@@ -76,6 +76,10 @@ class StringInflectionsTest < ActiveSupport::TestCase
end
end
+ def test_upcase_first
+ assert_equal "What a Lovely Day", "what a Lovely Day".upcase_first
+ end
+
def test_camelize
CamelToUnderscore.each do |camel, underscore|
assert_equal(camel, underscore.camelize)