String Methods in Ruby on Rails

A number of string manipulation methods are made available within Ruby to easily
manipulate the string. Some of the most common manipulation methods are

"Hello John".downcase #=> "hello john"

"Hello John".upcase #=> "HELLO JOHN"
"hello john".capitalize #=> "Hello john"
"Hello John".swapcase #=> "hELLO jOHN"
"Hello John".reverse #=> "nhoJ olleH"

These string manipulation methods can also be used inline to manipulate a variable

by appending an exclamation mark to the method:

hello = "Hello John"

hello.downcase!
puts hello #=> "hello john"

Further string methods are available within Ruby to interpret a string in a

number of ways:

"Hello John".length #=> 10

"Hello John".empty? #=> false
"1000".to_s #=> "1000" #Cast & Output to String
"1000".to_i #=> 1000 #Cast & Output to Integer
"1000".to_f #=> 1000.0 #Cast & Output to Float