Remove the first character from a Ruby string using [1..n]

I am trying to basically try to delete .in line.extension

So i use

'.extension'[1..10] #gives extension

Of course, this will work for 10 characters, as if I could make it work for any length. I do not know what to look for, because I do not know what this array style is called [x..y].

+3
source share
1 answer

You can use negative indexes. This compensates them from the very end. -1 is the last element, -2 is the second, etc.

'.extension'[1..-1] # => extension
+17
source

All Articles