From: Gavin Sinclair Date: 2004-05-08T21:08:59+09:00 Subject: How to get the last 5 elements of an array? Hi, I want to extract the last 5 elements of an array 'x'. I know that x is an array, but I don't know how many elements it has. What do you suggest? In code, this is what I want. def last5(arr) # Fill me in. end last5 [] # -> [] last5 [1] # -> [1] last5 [1,2] # -> [1,2] last5 [1,2,3,4,5,6,7] # -> [3,4,5,6,7] last5 nil # -> error Thanks, Gavin