【发布时间】:2009-07-21 00:38:19
【问题描述】:
所以我这里有这个哈希,我有一个循环。当循环检测到散列已经有一个值 vendor = "something" - 并且循环的值是 "something" - 我希望它只是去散列并更新一些值(价格,访问)。
为了简化这一点,基本上我有一个哈希数组,当我发现我已经有一个具有特定供应商值的哈希时,我想更新哈希(只更改价格和访问量)。
供您参考,我的 catlists 对象看起来像这样 -- @catLists = {[1] => {:vendor, :price, :visits, :month, :type}, [2] => {:vendor , :price, :visits, :month, :type}, [3] => {:vendor, :price, :visits, :month, :type} 等}
@income.each do |query|
queriedmonth = Date::MONTHNAMES[query.postdate.month]
thevendor = query.detail.capitalize
theprice = query.amount
numvisits = 1 #change this later
hit = "no"
@catLists.each do |item|
if (item.has_value?(thevendor))
hit = "yes"
//So here I want to update the hash in my catLists array.
end
end
if (hit=="no")
vendorlist << thevendor
@catList = {:vendor => thevendor, :price => theprice, :visits => numvisits, :month =>queriedmonth, :type=> "income"}
#Push onto our array
@catLists << @catList
end
end
我该怎么做呢?
感谢您的帮助,对于这个问题的复杂性,我们深表歉意。有点奇怪,我找不到这样做的好方法。
【问题讨论】:
标签: ruby-on-rails ruby arrays