Look carefully at the error:
p "hi".to_s +'/' p "hi".to_s -'2' #=> in `<main>': undefined method ` +@ ' for "/":String (NoMethodError)
This is because unary operator + , - , etc. defined only by objects of the Numeric class. It will be clear if you look at the code below:
p "hi".to_s +2
Now the above error exactly matches to_s . Since to_s does not accept any arguments when called.
The correct version is:
p "hi".to_s + '2'
Arup rakshit
source share