# IntegreMatrix

**URL:** <https://www.ruby-forum.com/t/integrematrix/115571>\
**Category:** Ruby\
**Created:** [September 26, 2007, 1:50pm UTC](https://www.ruby-forum.com/t/integrematrix/115571 "2007-09-26T13:50:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jngo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e95f7d/32.png) [@jngo](https://www.ruby-forum.com/u/jngo)\
**Post date:** [September 26, 2007, 1:50pm UTC](https://www.ruby-forum.com/t/integrematrix/115571/1 "2007-09-26T13:50:45Z")

</div>

Hello All,  
I have put together some code (using a book as a guide!!) to create an  
integer matrix as follows:

class IntegerMatrix

def initialize(rows,cols)  
@rows, @cols = rows, cols  
@data = (0…rows).map{(0…cols).map{0}}  
end

attr\_reader :rows, :cols

def dimensions  
[self.rows,self.cols]  
end

def get(rowidx, colidx)  
@data[rowidx][colidx]  
end  
alias [] get

def put(rowidx,colidx,value)  
raise TypeError “non integer value in IntegerMatrix” unless  
value.is\_a? Integer  
@data[rowidx][colidx]=value  
end  
alias []= put  
end

def to\_s  
(0…self.rows).map{|r|  
(0…self.cols).map{|c| “%5d”%self[r,c]}.join(" “)  
}.join(”\n")  
end

testm = IntegerMatrix.new(2,3)  
testm[0,0]=68; testm[0,1]=94; testm[0,2]=-2  
testm[1,0]=11; testm[1,1]=7; testm[1,2]=50

puts testm

and produces my test matrix as follows:

68 94 -2  
11 7 50

my problem is how do i take it to the next level so that it will read a  
.csz file and populate the matrix with its contents?.. is there a  
straight forward way to do this?.. or does anyone know any good  
websites/resources that can help with this.

Cheers!

- John

#####################################################################################  
This e-mail message has been scanned for Viruses and Content and cleared  
by MailMarshal  
#####################################################################################
