比方说,我们有一个哈希:转换哈希字符串在Ruby中
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
Tha t解决了我的问题,但也许有更好的解决方案在hashtable类中构建?
是啊,这就是我一直在寻找;) – 2009-06-24 13:31:34