I have a function in Ruby:
def find_item(keyword)
potential = []
$items.each do |item|
puts item # <-- for debugging purposes
if item["name"].downcase== keyword
potential << item["name"].downcase
elsif item["keywords"].index(keyword) != nil
potential << item["name"].downcase
end
end
return potential
end
(The global variable $items is a Hash object that maps a few strings to some values that determine the properties of the item.)
When I puts the current item it is iterating over (the line with the comment does just that), it gives me:
{"name"=>"Thing1", "keywords"=>["thing", "green"], ...}
but when I try item["name"] on the next line (which should definitely return Thing1), it gives me:
C:/somepath/someprogram.rb:125:in '[]': can't convert String into Integer (TypeError)