From: David Tillman Date: 2001-07-28T04:49:12+09:00 Subject: [ruby-talk:18662] How to collect question Hello all, I have been coding in Ruby for a few days now and have some questions. I understand (I think) about telling collect to an array as exhibited by the table method below. I would like to do something similar in the method table_fancy but had to use a temp var, x, to make it work. Any ideas on how I can eliminate the x? class Array def table (*args) alf = HTMLtable.new(*args) self.each { |r| alf << trow (r.collect! { |c| tcell (c)})} alf.to_s end def table_fancy (format, *args) alf = HTMLtable.new(*args) x = '' self.each { |row| 0.upto (row.length - 1) { |i| x << tcell (row[i], *format[i]) } alf << trow (x) x = ''} alf.to_s end end This is an excerpt from my HTML lib that I wrote for Scheme and am porting to Ruby. The above functions would be called as: doc = HTMLdoc.new(H_title => 'Some Document') foo = [['red', 'green', 'blue'], ['moe', 'martin', 'alf']] format = [[H_th => true], [H_bgcolor => '#ddffdd'], []] doc << foo.table (H_border => 1) doc << foo.table_fancy (format, H_border => 1) puts doc Thank you for you thoughts, -Dave