提交 7047e556 编写于 作者: G Glauco Custódio

Add upcase_first method

上级 f78d0ede
* Add `String#upcase_first` method.
*Glauco Custódio*
## Rails 5.0.0.beta3 (February 24, 2016) ##
* Deprecate arguments on `assert_nothing_raised`.
......
......@@ -222,6 +222,13 @@ def humanize(options = {})
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'.
......
......@@ -140,6 +140,13 @@ def humanize(lower_case_and_underscored_word, options = {})
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.
......
......@@ -76,6 +76,10 @@ def test_titleize
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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册