Fill a table in ruby

Hi,

I want to read the datas from a file and fill a table with them.
All lines will be a new row for table. And the columns are for the
variables of the class.

I want to create an array as an object of a class for this. But i don’t
know how to do it.

Class Abc
@a
@b

end

a[100]=Abc.new()

so for example a[0] will be the first row of the table and a[0].a will
be the first column of the table

i want to do sth like that.

How can i do it? Or is there another way to fill a table in ruby?

Sounds like a matrix class might work for you
http://ruby-doc.org/stdlib/libdoc/matrix/rdoc/classes/Matrix.html

“Brk A.” [email protected] wrote in message
news:[email protected]

@a
i want to do sth like that.

How can i do it? Or is there another way to fill a table in ruby?

Posted via http://www.ruby-forum.com/.

Use an array of structs as in the folloving snippet:

class Table
def initialize # define table structure and array for data
@template = Struct.new(:name, :age)
@data = []
end # initialize

def add_row(_name, _age)
[email protected](_name, _age)
@data << s
end # add_row
def out_rows
@data.each { |s| printf(“%-10s %4d\n”, s.name, s.age) }
end # out_rows

end # class Table

tbl = Table.new() # create a table and add some rows
tbl.add_row(‘frank’, 40)
tbl.add_row(‘tina’, 30)

tbl.out_rows() # print the content of the table
exit(0)
END

hth gfb

Thank you i was looking sth like that.