How can one use send
with +=
?
a = 20; a.send "+=", 10
undefined method `+=' for 20:Fixnum
a = 20; a += 10
=> 30
I'm afraid you cannot. +=
is not a method, but rather syntactic sugar.
See http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html
It says
In common with many other languages, Ruby has a syntactic shortcut: a=a+2 may be written as a+=2.
Best you can do is:
>> a = 20
=> 20
>> a = a.send "+", 10
=> 30
>> a
=> 30
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With