Tim Pease
2/13/2007 7:27:00 PM
On 2/13/07, WKC CCC <wai-kee.chung@uk.bnpparibas.com> wrote:
> Thanks,
>
> I've created the following function as an extention to class Array:
>
> def Section(startRow,nRows,startCol,nCols)
> part = self[startRow..startRow+nRows-1]
> part = part.map{|x| x[startCol..startCol + nCols-1]}
> return part
> end
>
> testArray=[[1,2,3,4,5],
> [6,7,8,9,10],
> [11,12,13,14],
> [15,16,17,18]]
>
> calling testArray.Section(2,2,2,2)
>
> will return [[13,14],[17,18]]
>
def section( rows, cols )
self.slice(rows).map! {|c| c.slice(cols)}
end
testArray = [
[1,2,3,4,5],
[6,7,8,9,10],
[11,12,13,14,15],
[16,17,18,19,20]
]
testArray.section( 2...4, 2...4 )
[[13, 14],
[18, 19]]
Blessings,
TwP