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 answers

i'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

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -