From: "Diego N." Date: 2013-07-17T01:21:33+09:00 Subject: Re: Get part of matrix First, thanks Carlos Agarie and Stefano Crocco for help me! :) I decided to use the native Matrix class... but i needed to get square around 54, for instance: I'm trying to make a method: def build_matrix(r=0, c=0) m = Matrix.build(c, r) {|row, col| col + (row * r) } end def my_method(position, size) rows_size = 10 cols_size = 10 matrix = build_matrix(rows_size, cols_size) area = position - (Math.sqrt(size).to_i * rows_size) - Math.sqrt(size).to_i return matrix.minor(matrix.index(area)[0], size,matrix.index(area)[1], size) end = my_method(54, 3) -> Matrix[[43, 44, 45], [53, 54, 55], [63, 64, 65]] = my_method(54, 3) -> Matrix[[32, 33, 34, 35, 36], [42, 43, 44, 45, 46], [52, 53, 54, 55, 56], [62, 63, 64, 65, 66], [72, 73, 74, 75, 76]] Where i pass 54(name of position) and 3(area of square). It work! But, if i pass 40, for instance not work as well, because 40 is on the corner... Anyone knows if the matrix class can do this easier? get the square around 54. 54 is my center.. On position 40, it should return ( 30, 31, 41, 50, 51).. Thanks on more time! Diego -- Posted via http://www.ruby-forum.com/.