Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I assume that with session, you mean an open irb (interactive ruby), but this suggestion not limited to that.</p> <p>The first thing to do is to initialize your data. It does not matter if you store the data as a global variable or as a local one that you pass around as parameters, because ruby passes parameters as references. When you change the code that works with the data, you should use the 'load' statement instead of 'require', because load forces ruby to parse the file again.</p> <p>For example, lets say you have initialize your data in your irb</p> <pre><code>&gt; data = (1..120).to_a =&gt; [1, 2, ...] </code></pre> <p>(Note that irb prints the array to the shell, so that initializing a large array with give you a lot of numbers running across your screen.) And your code that uses that data in a file called loadable.rb</p> <pre><code>def some_number(data) data[100] end </code></pre> <p>Now you can load that file into irb and call the function.</p> <pre><code>&gt; require 'loadable' =&gt; true &gt; some_number(data) =&gt; 101 </code></pre> <p>When you change the code in loadable.rb to (let say) return the entry 10 instead of 100, reload the file, and call the function again, you will get different results for require and load.</p> <pre><code>&gt; require 'loadable' =&gt; false &gt; some_number(data) =&gt; 101 </code></pre> <p>With require, you get the old (wrong) result.</p> <pre><code>&gt; load 'loadable.rb' =&gt; true &gt; some_number(data) =&gt; 11 </code></pre> <p>With load you get the desired results. Note that you need to call load with the complete filename, including the '.rb'.</p> <p>You could do this even without irb, by having one ruby program that initializes the data and then waits for changes in the other files in a loop, loads them again, and calls their functions.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload