如何创建这个多重数组、哈希组合?
我有 此数据,我需要类似这种类型的输出。我基本上需要拥有所有场地和他们的日期以及与他们相关的所有歌曲...如果有人能想到更好的结构以及如何实现它,我将非常感激...
{
["Vector Arena - Auckland Central, New Zealand" =>
{
"2010-10-10" => ["Enter Sandman", "Unforgiven", "And justice for all"]
}],
["Brisbane Entertainment Centre - Brisbane Qld, Austr..." =>
{
"2010-10-11" => ["Enter Sandman"]
}]
}
到目前为止我尝试过这个...并且不确定我是否要搬进来正确的方向..
@venues = Hash.new {|hash, key| hash[key] = 0}
@requests = Request.find_all_by_artist("Metallica")
@requests.each do |request|
@venues[request.venue] = request.showdate
end
I have this data and i need an output like this type of output.. I basically need to have all the venues and their dates and all the songs associated to them ....if anyone can think of a better structure and how to achieve it I would be very thankful...
{
["Vector Arena - Auckland Central, New Zealand" =>
{
"2010-10-10" => ["Enter Sandman", "Unforgiven", "And justice for all"]
}],
["Brisbane Entertainment Centre - Brisbane Qld, Austr..." =>
{
"2010-10-11" => ["Enter Sandman"]
}]
}
so far i tried this...and not sure if i am moving in the right direction..
@venues = Hash.new {|hash, key| hash[key] = 0}
@requests = Request.find_all_by_artist("Metallica")
@requests.each do |request|
@venues[request.venue] = request.showdate
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个有效的解决方案:
Here is an efficient solution:
我认为你的结构不太正确。它应该像
尝试这个代码
希望你至少明白这个想法。
I think you structure is not quite right. It should be like
Try this code
Hope you get the idea at least.