危機感があるなら明かりつけようぜ。>>537と>>554を矯正すると

html=String.new
html << '<html><titile>CGIテスト</titile><body>'
(0..3).each{|i| 
html << i + '<br>' # 色々処理
}
html << '</body></html>'

cookie = CGI::Cookie::new({
'name' => 'name',
'value' => 'TEST',
'expires' => Time.now + 60 * 60 * 24
})
header={
"cookie" => cookie,
"charset" => "shift_jis"
}
cgi=CGI.new
cgi.out(header){html}

たとえばこんな感じか?