title: How to save a hash in a file and use it later in ruby?
body: <p>So i got in big troubles with this exam at university because i am stuck with a part in my ruby code. I just can't figure out how </p>
  
  <p>" If the user presses 2 the program shall ask for an employee number and afterwards search for the employee. If the program finds it, then print and if not, print a message saying it doesn’t have it."</p>
  
  <p>My problem is that i'm not sure that the information is saved corectly in the file. But if it is... the problem is that the hash i've made isn't taking the information that already is saved in the file and only works with the information it has received last.</p>
  
  <pre><code>puts "Insert Registration number \n"
  search = gets.chomp
  
  hash = Hash.new()
  hash = {(regnr) =&gt; (name)}
  hash.each do |key, value|
    puts "#{key} \t | \t #{value}"
  end
  
  search =~ File.new("employees.txt", "r")
  
  if hash.has_key? (search)
    print "The person you were looking for is "
    puts hash [search]
  else
    puts "He isn't one of our employees"
  end
  </code></pre>
  
  <p>I have to tell you guys that i have only been coding for one month and the school isn't taking me easy...</p>