The chr
method removes the first character of a string in Ruby. It removes the one-character string at the beginning of a string and returns this character.
str.chr
str
: This is the string that calls the chr
method.
The string’s first character is returned, which calls the chr
method.
# create some stringsstr1 = "Welcome"str2 = "to"str3 = "Edpresso"# remove first charactersa = str1.chrb = str2.chrc = str3.chr# print returned valuesputs aputs bputs c
As we can see above, the first characters of the strings were removed and printed out on the console.