Printing of characters


#1

Can someone please explain to me the bellow part of code:

# method that capitalizes a word
def capitalize(string)
  puts "#{string[0].upcase}#{string[1..-1]}"
end

#{string[1..-1]}

What confuses me is this part: #{string[1..-1]}
this should loop through every character in the string, from second char to the last one. But how does this work with this part [1..-1] I would expect it to look something like [1..5], which would mean loop through characters from second to fifth.

Thanks,


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.