ruby - What does array[1..-2] mean? -
ruby - What does array[1..-2] mean? -
this question has reply here:
how negative index work `array#[]=`? 3 answersi've come across code snippet index access defined range ending minus value.
array[1..-2]    what's purpose of this?
in ruby (as python, perl, , few other languages), negative array index interpreted relative end of array. array[-1]  lastly element of array; array[-2] next last.
so piece of array omitting first , lastly elements.
 ruby arrays range 
 
Comments
Post a Comment