aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorGlauco Custódio <glauco.custodio@gmail.com>2016-02-25 23:05:54 -0300
committerGlauco Custódio <glauco.custodio@gmail.com>2016-02-25 23:05:54 -0300
commit7047e5562118d23c66c390b004f74ed35b90ab14 (patch)
treee1006cecad56da16d66709ea8d99dffcf1237cf5 /activesupport/lib/active_support
parentf78d0eded3266918242027dab6bd10d07bcb55d5 (diff)
downloadrails-7047e5562118d23c66c390b004f74ed35b90ab14.tar.gz
rails-7047e5562118d23c66c390b004f74ed35b90ab14.tar.bz2
rails-7047e5562118d23c66c390b004f74ed35b90ab14.zip
Add upcase_first method
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/core_ext/string/inflections.rb7
-rw-r--r--activesupport/lib/active_support/inflector/methods.rb7
2 files changed, 14 insertions, 0 deletions
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.