 <p><code>String#to_i</code> returns a new Object (which is the only sensible implementation; think a moment about what would happen if <code>String#to_i</code> magically changed the object's class).</p> <p>So, to assign the integer value to your <code>sum</code> variable, use</p> <pre><code> sum = sum.to_i </code></pre> <p>or (better) introduce a new variable for your integer value:</p> <pre><code> sum_as_integer = sum.to_i </code></pre>