vesper967 0 Newbie Poster

So I'm writing a program that reads in a file which has each word on a different line. The program is supposed to loop through the file in such a way that when it reads a line and gets to the end of the line it adds that word to an array and inserts it into a trie that I have created then it does it for the second, third and so on. However, every time I insert a new word the existing trie is overwritten. How can I loop through so that my trie continues to hold on to the previously inserted words? And yes I know that my code is probably written horribly.

def hw2
  puts "What file would you like to read?"
  name = gets.chomp
  puts "What file would you like to write to?"
  name2 = gets.chomp

  f1 = File.new(name2, "w+")
  aFile = File.open(name, "r")
  array = []
  while char = aFile.getc
    char = char.each_byte { |ch| } 
    array.push char
    first = array.first
    rest = array.reverse
    rest.pop
    rest = rest.reverse
    t2 = insert(first, rest)
    
    if char == "\n"
     array.clear
    end
  end

    print t2
    print "\n"
end