【发布时间】:2010-11-05 12:20:10
【问题描述】:
假设我们有一个哈希:
flash = {}
flash[:error] = "This is an error."
flash[:info] = "This is an information."
我想把它转成字符串:
"<div class='error'>This is an error.</div><div class='info'>This is an information".
在一个不错的班轮中;)
我发现了类似的东西:
flash.to_a.collect{|item| "<div class='#{item[0]}'>#{item[1]}</div>"}.join
这解决了我的问题,但也许哈希表类中有更好的解决方案?
【问题讨论】: