1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| require 'erb'
def table_helper(map)
body = map.collect do |item|
"<tr><td>#{item[0]}</td>
<td>$#{item[1]}</td></tr>\n"
end
return("<table>\n#{body}</table>")
end
map = {
"Peaches" => "1.95",
"Apples" => ".95"
}
template = ERB.new <<-EOF
<p>Here's our price list</p>
<%= table_helper(map) %>
EOF
puts template.result
|