Using Matrix properities in ror

Hi,

I need to know how to make use of matrix in my ruby on rails application
as I am clearly clueless.
Let me give you an example to understand it better.

If I have a 2x4 matrix how would I carry out the functionality of adding
two neighboring cell values .

Evin more important how would I be able to UPDATE THE MATRIX DYNAMICALLY
to then

perform the above functionality.

Thank You