I'm trying to iterate through database file with gdbm, create objects with values I get and assign them to an array. The problem is I can't seem to get index of iteration and I need it for my array. Here is the code:
bots_directory = "../data/bots.db"
bots = Array.new
GDBM.new(bots_directory).each_pair.with_index do |nickname, password, index|
bots[index] = Bot.new(nickname, password)
end
Error I get:
`[]=': no implicit conversion from nil to integer (TypeError)
Also, will database file close after the block is executed?