Ok that worked but the code below gives garbage with objects.


class TestObject
   attr_reader :data
    
   def initialize(val1, val2)
     @data = [val1, val2]
   end
end

class Test
   def initialize
      createObjects
      doHTML
   end
   
   def createObjects
      @data = Array.new
      for num in 1..10 do
         @data << TestObject.new (num, num  * 10)
      end
   end
   
   def doHTML
      cgi = CGI.new("html3")
      cgi.out{
         cgi.head{ "\n"+ cgi.title{"Test"} } +
           cgi.body{
             cgi.h1 { "Test" } +
              cgi.table do
                  @data.each do |testObject|
                     cgi.tr do                           
                         testObject.data.each do |value|
                            # output is: 10 100 20 200...
                            # puts "#{value}" 
                            res = ""
                                                           
                            # output is: <TestObject:0x2b20588>#<TestObject:0x2b20570>... 
                            res += cgi.td {"#{value}"} 
                            res
                         end
                     end # tr
                  end # @data
              end # table
          } # body
        }
   end
end


6/6/2003 3:06:24 PM, "Simon Strandgaard" <0bz63fz3m1qt3001 / sneakemail.com> wrote:

>On Sat, 07 Jun 2003 04:27:32 +0900, Steven Ketcham wrote:
>
>> Perhaps I'm doing this wrong?
>> 

...snip...

>
>You are not 'plus'ing the <td> elements.
>
>try this:
>
>> cat xxx.rb
>require "cgi"
>cgi = CGI.new("html3")  # add HTML generation methods
>cgi.out() do
>        cgi.html() do
>                cgi.head{ cgi.title{"TITLE"} } +
>                cgi.body() do
>                        cgi.table do
>                                cgi.tr do
>                                        res = ""
>                                        [1, 2, 3, 4].each { |col| res += cgi.td {"#{col}"} }
>                                        res
>                                end
>                        end
>                end
>        end
>end
>> ruby xxx.rb x
>Content-Type: text/html
>Content-Length: 178
>
><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2
>Final//EN"><HTML><HEAD><TITLE>TITLE</TITLE></HEAD><BODY><TABLE><TR><TD>1</TD><TD>2</TD><TD>3</TD><TD>4</TD></TR></TABLE>
</BODY></HTML>
>>
>
>--
>Simon Strandgaard
>
>
>