From: OZAWA Sakuro Date: 1999-07-25T04:59:12+09:00 Subject: [ruby-talk:00520] Re: CGI.rb > I am using CGI.rb. It's very nice. > But, is it possible to create tables with it? Assuming you mention 'cgi-lib.rb', its CGI class defines no method for table generation. For some very simple cases, following code might help. It asumes no spanning(holds two or more) columns/rows, and handles little cosmetics. It would be nice to have servlet classes for ruby...:-) -- OZAWA Sakuro ------------------------( C U T H E R E )--------------------------- # require 'cgi-lib.rb' class CGI def table(headings, rows, border=nil) if border if border.kind_of?(String) and /^\d+[a-zA-Z]*/ =~ border result = "\n" else result = "
\n" end else result = "
\n" end result << "" headings.each do |item| result << "" end result << "\n" rows.each do |row| result << "" row.each do |item| result << "" end result << "\n" end result << "
#{item}
#{item}
\n" end end # sample headings = [ "Name", "Age" , "Sex" ] rows = [ [ "Jack", "30", "M" ], [ "Betty", "29", "F" ] ] # x = CGI.new print x.table(headings, rows) print x.table(headings, rows, true) print x.table(headings, rows, "5px")