Reverse indexing (was RE: Ruby and WMI)

#C:\family\ruby>irb --simple-prompt
#>> x=[0,1,2,3,4,5]
#=> [0, 1, 2, 3, 4, 5]
....

#otherwise, these will return empty arrays

···

#
#>> x[-1..2]
#=> []
#
#>> x[-1..-5]
#=> []
#
#>> x[-1..-4]
#=> []
#

on the second thought, what if ruby allows the above such that,

considering index equivalence for x:

0 1 2 3 4 5
-6 -5 -4 -3 -2 -1

x[-1..2]

=> [5,4,3,2]

x[-1..-5]

=> [5,4,3,2,1]

x[-1..-6].each{|x| print x}

543210 =>[5,4,3,2,1,0]

and since arrays are ordered, we may have notation for reverse traversal of array ..

dunno, just nuby here.

kind regards -botp

Did you know you can use reverse_each?

x = (0..5).to_a
x.reverse_each do |i|
  print i
end
#=> 54321

Regards,

Sean

···

On 11/23/05, Peña, Botp <botp@delmonte-phil.com> wrote:

and since arrays are ordered, we may have notation for reverse traversal of array ..