Can someone explain this line for me?


If someone could explain to me why the string[1..-1] part works on the below code. I just don't seem to understand why it would be -1. Probably a really simple answer but thanks anyway...

def capitalize(string) 
  puts "#{string[0].upcase}#{string[1..-1]}"


Try the documentation, it describes what negative indexes do


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