Ruby string slice index: str[n..infinity]

Use reverse indexing:

[1..-1]

An element in Ruby (and some other languages) has straight forward index and a “reversed” one. So, string with length n has 0..(n-1) and additional (-n)..-1 indexes, but no more — you can’t use >=n or <-n indexes.

  'i' 'n'|'A' 'u' 's' 't' 'i' 'n'|'A' 'u' 's' 't' 'i' 'n'|'A' 'u' 's'
  -8  -7  -6  -5  -4  -3  -2  -1   0   1   2   3   4   5   6   7   8 
<- error |                you can use this               | error ->

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)