Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ruby is a <a href="https://stackoverflow.com/questions/3462405/terminology-what-features-must-a-language-have-for-it-to-be-considered-a-dynami"><em>dynamically-typed</em></a>, <a href="https://stackoverflow.com/questions/805168/what-is-a-strictly-typed-language"><em>strictly-typed</em></a> (or "strongly-typed") language. Lua is another such language. The former means that variables can hold any class of value. The latter—what you are running into—means that type coercion does not happen automatically. </p> <p>Contrast these with JavaScript, which is dynamically-typed and <em>loosely-typed</em>. In JavaScript you can write <code>var x = [] + false;</code> and it will <em>attempt</em> to do something helpful. For another example, in JavaScript <code>"1" + 1 == "11"</code> but <code>"1" - 1 == 0</code>. Ruby will not do any such thing.</p> <p>In your case you need:</p> <pre><code>puts income.to_i - bills.to_i </code></pre> <hr> <p>Note that—because most <a href="http://phrogz.net/ProgrammingRuby/language.html#operatorexpressions" rel="nofollow noreferrer">operators are implemented as methods</a> in Ruby—each class can choose how the operator handles operands of various types. For example:</p> <pre><code>class Person def +( something ) if something.is_a?(Numeric) self.weight += something elsif something.is_a?(Time) self.age += something else raise "I don't know how to add a #{something.class} to a Person." end end end </code></pre> <p>Most of the time the core libraries do not attempt to be so clever, however.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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