What does string[1..-1] do?


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

what does string[1…-1] do?
<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>

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

capitalize(“ryan”) # prints “Ryan”
capitalize(“jane”) # prints “Jane”

block that capitalizes each string in the array

[“ryan”, “jane”].each {|string| puts “#{string[0].upcase}#{string[1…-1]}”} # prints “Ryan”, then “Jane”


Replace this line with your code. 



#2

@jkm345,

Have a look at some documentation

http://www.rubyist.net/~slagell/ruby/strings.html
http://stackoverflow.com/questions/3611586/ruby-string-slice-index-strn-infinity
https://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Literals#Interpolation


#3

It goes from the second element to the last element of the array.
Ex. a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] puts "#{a[1..-1]}" #=> [2, 3, 4, 5, 6, 7, 8, 9, 10]


#4
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
puts "#{a[1..-1]}"

will output,

2345678910

since it only outputs the values, not the array.

In the case of a string,

b = 'everyday hero'
puts "#{b[1..-2]}"

will output,

veryday her