Strong vs. weak typing $> 3 + “a” Python: unsupported operand type(s) for +: 'int' and 'str' Ruby: String can't be coerced into Fixnum Javascript: “3a”
Strong vs. weak typing $> 3 + “a” Python: unsupported operand type(s) for +: 'int' and 'str' Ruby: String can't be coerced into Fixnum Javascript: “3a”
Bad solution class Fixnum alias :old_multiply :* def *(val) if defined?(Money) && val.is_a?(Money) return self * val.amount else old_multiply(val) end end end
How does it work? Short answer: when Ruby can’t handle the param type, it calls arg.coerce(self) it gets 2 elements array, and calls array[0].method(array[1])