我有一个 Ruby 哈希,例如:
{"monkeys"=> {"hamburgers" => ["love", "eat"],
"boulders" => ["hate", "throw"]},
"stonemasons" => {"boulders" = > ["love", "use"],
"vandals" => ["hate", "sue"]}
}
它可以具有几乎任何级别的深度(我可以将散列放入散列中任意次数)。它总是将数组作为最终值。
如何在不使用 Rails 并且最好只使用标准库的情况下将其解析为如下所示的 HTML 表格?
<table>
<tr>
<th rowspan="2">monkeys</th>
<th>hamburgers</th>
<td>love</td>
<td>eat</td>
</tr>
<tr>
<th>boulders</th>
<td>hate</td>
<td>throw</td>
</tr>
<tr>
<th rowspan="2">stonemasons</th>
<th>boulders</th>
<td>love</td>
<td>use</td>
</tr>
<tr>
<th>vandals</th>
<td>hate</td>
<td>sue</td>
</tr>
</table>