【发布时间】:2015-11-02 08:25:51
【问题描述】:
我有一个名为sales_hash 的哈希值,我正在打印出来。每个散列都有一个名为sku 的键,它与array_items 数组中的散列匹配。我从数组中取出散列,并尝试根据 :item 的键打印散列的值,但我不断收到错误消息。我做错了什么?
sales_hash.take(10).each do |a, b|
temp_hash = array_items.select{|array_items| array_items[:sku] == a}
puts temp_hash
puts "Sku is #{a} the amount sold is #{b} the name of the book is #{temp_hash[:price]}"
end
#{temp_hash[:item]}" 行一直给我一个错误
【问题讨论】:
-
错误信息是什么?
-
做:
puts temp_hash.inspect看看你在temp_hash里面得到了什么 -
@DJ 错误信息是 rb:59:in `[]': no implicit conversion of Symbol into Integer (TypeError)
-
@KMRakibulIslam,我得到了项目的哈希 [{:item=>["cornish_heath"], :price=>24.33, :sku=>236131}]
-
那不是散列,那是散列数组。