title: How to run a Ruby script in interactive mode
body: <p>In MATLAB, if one writes a script and runs it, the variables defined in the script are available at the command line prompt. I would like to do something similar with IRB or Pry. I wrote a script called "scratch.rb" which simply reads</p>
  
  <pre><code>x = 0
  </code></pre>
  
  <p>If I type "irb" in the command line in the same directory as this script and type</p>
  
  <pre><code>&gt; load 'scratch.rb'
  </code></pre>
  
  <p>This appears to run the Ruby script (as I've confirmed by adding a p command). However, if immediately thereafter I try to 'echo' the variable x by</p>
  
  <pre><code>&gt; x
  </code></pre>
  
  <p>I get an error</p>
  
  <pre><code>NameError: undefined local variable or method `x' for main:Object
  </code></pre>
  
  <p>Is it possible to make the variables available interactively in this way?</p>