The string.capitalize()
function in Ruby does not modify the original string, but instead returns a copy of the original string, in which the first letter is capitalized and the remaining letters are lower case.
Figure 1 shows the visual representation of the string.capitalize()
function.
string_name.capitalize()
# string_name is the name of the string to be capitalized
This function does not require a parameter.
This function returns the copy of the original string, in which the first letter is capitalized and the remaining letters are lower case.
The following code shows how to use the string.capitalize()
function.
# working example of string.capitalize()print "('hello').capitalize() : ", ('hello').capitalize(), "\n"print "('educative').capitalize() : ", ('educative').capitalize(), "\n"