編輯:問題是無法獲取散列內數組的數量,因此它可以是x =數組量。所以它可以用作function.each_index {| x |代碼}無法將符號轉換爲散列表中的整數
嘗試使用行的量的指數爲依賴於有多少數據從CSV文件拉出重複次數的動作X量的一種方式。
終端發出
=> Can't convert symbol to integer (TypeError)
完全錯誤:
=> ~/home/tests/Product.rb:30:in '[]' can't convert symbol into integer (TypeError) from ~home/tests/Product.rub:30:in 'getNumbRel'
from test.rb:36:in '<main>'
功能是執行的操作是:
def getNumRel
if defined? @releaseHashTable
return @releaseHashTable[:releasename].length
else
@releaseHashTable = readReleaseCSV()
return @releaseHashTable[:releasename].length
end
end
CSV數據拉只是一個數組的哈希,沒什麼時髦的。
def readReleaseCSV()
$log.info("Method "+"#{self.class.name}"+"."+"#{__method__}"+" has started")
$log.debug("reading product csv file")
# Create a Hash where the default is an empty Array
result = Array.new
csvPath = "#{File.dirname(__FILE__)}"+"/../../data/addingProdRelProjIterTestSuite/releaseCSVdata.csv"
CSV.foreach(csvPath, :headers => true, :header_converters => :symbol) do |row|
row.each do |column, value|
if "#{column}" == "prodid"
proHash = Hash.new { |h, k| h[k] = [ ] }
proHash['relid'] << row[:relid]
proHash['releasename'] << row[:releasename]
proHash['inheritcomponents'] << row[:inheritcomponents]
productId = Integer(value)
if result[productId] == nil
result[productId] = Array.new
end
result[productId][result[productId].length] = proHash
end
end
end
$log.info("Method "+"#{self.class.name}"+"."+"#{__method__}"+" has finished")
@productReleaseArr = result
end
你可以加回溯 – krichard
@kritchard mhm也許是noob問題,但究竟是回溯? – samayres1992
整個錯誤消息。 –