我有一个名为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]}"
不断给我一个错误
什么是错误信息? –
Do:'puts temp_hash.inspect'并且看看你在'temp_hash'里面得到了什么 –
@DJ错误信息是rb:59:在'[]'中:没有将符号隐式转换为整数(TypeError) – Aaron