Why does ruby addition cannot coerce given string to fixnum and vice verca?
irb>fixnum = 1
=> 1
irb> fixnum.class
=> Fixnum
irb> string = "3"
=> "3"
irb> string.class
=> String
irb> string.to_i
=> 3
irb> fixnum + string
TypeError: String can't be coerced into Fixnum
from (irb):96:in `+'
from (irb):96
from :0
irb(main):097:0>
Because ruby doesn’t know whether you want to convert the string to int or the int to string. In e.g. java
1 + "3"is"13". Ruby prefers to raise an error, so that the user can decide whether toto_sthe one operand orto_ithe other, rather than doing the wrong thing automatically.