title: Ruby: File dialog wont close
body: <p>I am using the ruby gem <code>gtk2</code> to display a simple file dialog, where the user can select a file from his computer. It works just fine, however there is one little problem.</p>
  
  <p>The file dialog doesnt close after selecting the file, but it stays open until the whole script finished.</p>
  
  <p>My file dialog looks like this:</p>
  
  <pre><code>def ask_for_file(question)
      dialog =  Gtk::FileChooserDialog.new(question, nil,
                           Gtk::FileChooser::ACTION_OPEN,
                           "gnome-vfs",
                           [Gtk::Stock::OPEN, Gtk::Dialog::RESPONSE_ACCEPT],
                           [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL]
                           )
      if dialog.run == Gtk::Dialog::RESPONSE_ACCEPT
          file_name = dialog.filename.to_s
          return file_name
      else
          return nil
      end
  end
  </code></pre>
  
  <p>When I call it in my script like this:</p>
  
  <pre><code>path = ask_for_file("Test?")
  sleep(5)
  puts "continue with #{path}"
  </code></pre>
  
  <p>The file dialog stays open for 5 seconds and is unresponsive in that time. How could I get it to close after a file has been selected, but before the 5 second sleep?</p>
  
  <p>I tried to use <code>dialog.destroy</code> in <code>ask_for_file</code> just before returning the <code>file_name</code> but that didnt seem to help.</p>