From: Steven Ketcham Date: 2003-06-07T05:35:26+09:00 Subject: Re: RUBY, CGI and objectts 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: #... 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 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 > >Final//EN">TITLE
1234
>> > >-- >Simon Strandgaard > > >