RosettaCodeData/Task/Create-an-HTML-table/Ruby/create-an-html-table-1.rb

23 lines
363 B
Ruby

def r
rand(10000)
end
STDOUT << "".tap do |html|
html << "<table>"
[
['X', 'Y', 'Z'],
[r ,r ,r],
[r ,r ,r],
[r ,r ,r],
[r ,r ,r]
].each_with_index do |row, index|
html << "<tr>"
html << "<td>#{index > 0 ? index : nil }</td>"
html << row.map { |e| "<td>#{e}</td>"}.join
html << "</tr>"
end
html << "</table>"
end