From: "Olivier D." Date: 2004-08-17T14:41:05+09:00 Subject: Re: Q: Shifting a hash anf and array On 2004-08-17, Meino Christian Cramer wrote: > Contents of the array before the trick: > > 1 2 3 4 5 6 7 8 9 0 index > A B C D E F G H I J contents > > Contents of the array after the trick: > > 1 2 3 4 5 6 7 8 9 0 index > J A B C D E F G H I contents I used my algorithm skills to come up with this strange solution: swap every consecutive values starting from the beginning of the array, which can be written with the methods: class Array def left_shift! each_index do |i| self[i], self[i+1] = self[i+1], self[i] if self[i+1] end end # of course you can prefer the cleaner: def left_shift_v2! obj = shift self << obj end def right_shift! obj = pop unshift obj end end -- Olivier D.