title: Reset state of embedded ruby interpreter
body: <p>I have an application with can be extended with Ruby. Scripts can be created in the application itself and are reloaded every time they are edited. So, when the user adds a method to a class, it takes effect immediately. I can't just execute the modified file, as if the user removes a method, it shall unexist. The only option is to clear the state of the interpreter and reload all scripts again. But Ruby protects itself against restarting: (<code>eval.c</code>)</p>
  
  <pre><code>void ruby_init(void)
  {
      int state = ruby_setup();
      if (state) {
          error_print();
          exit(EXIT_FAILURE);
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>int ruby_setup(void)
  {
      static int initialized = 0;
      int state;
  
      if (initialized)
          return 0;
      initialized = 1;
  
      /* ... */
  
      return state;
  }
  </code></pre>
  
  <p>I also think calling <code>ruby_init()</code> multiple times can cause issues with the stack position that ruby keeps track of and break the GC. Restarting the whole application is not an option as it has a GUI interface. Also keeping all ruby stuff in a separated process would be painful because a Qt interface to insert new GUI elements on the application is exposed. Another option is to keep track somehow of all defined methods, classes, constants, etc and undef them before reexecuting the code. Is there a simple way?</p>