@hash是一個全球性的哈希值,看起來像:爲什麼不能用於遞歸讀取哈希?
@hash = {
"xmlns:xsi" =>"http://www.w3.org/2001/XMLSchema-instance",
"xsi:noNamespaceSchemaLocation"=>"merchandiser.xsd",
"header" =>[{"merchantId"=>["35701"],
"merchantName" =>["Lingerie.com"],
"createdOn" =>["2011-09-23/00:33:35"]}],
"trailer" =>[{"numberOfProducts"=>["0"]}]
}
而且我希望這個工作如果我叫下面像方法:
def amethod
hash_value("header", "merchantName") // returns "Lingerie.com"
end
def hash_value *attributes, hash = nil
hash = @hash unless hash
att = attributes.delete_at.first
attributes.empty? ? hash[att].first : hash_value(attributes, hash[att].first)
end
至少不清楚(至少對我而言)是什麼問題;請添加失敗消息。 – jschorr
我實際上在hash_value聲明中得到了一個語法錯誤,但它看起來對我來說 –
請參閱提議的答案。 – jschorr