我正在尝试访问 sinatra 中的哈希数据:
require 'rubygems'
require 'sinatra'
class List
def self.items
return items = {
:something1 => { :attribute1 => "somestring1", :attribute2 => "somestring2" },
:something2 => { :attribute1 => "somestring3", :attribute2 => "somestring4" }
}
end
end
list = List.items
get '/' do
list.each do |name, meta|
"#{name}<br>#{meta[:attribute1]}<br>#{meta[:attribute2]}<br><br>"
end
end
我希望 sinatra 打印每个散列的散列数据。但是,它只打印了哈希值(可能是因为我调用了list.each
)。当我使用puts
.
为了澄清,期望的结果是:
something1
somestring1
somestring2
something2
somestring3
somestring4
如何让 sinatra 只打印变量?
谢谢!