Plus equals with ruby send message

ruby

Solution

I think the basic option is only:

a = a.send(:+, 1)

That is because `send` is for messages to objects. Assignment modifies a variable, not an object.

It is possible to assign direct to variables with some meta-programming, but the code is convoluted, so far the best I can find is:

a = 1
var_name = :a
eval "#{var_name} = #{var_name}.send(:+, 1)"
puts a  # 2

Or using instance variables:

@a = 2
var_name = :@a
instance_variable_set( var_name, instance_variable_get( var_name ).send(:+, 1) )
puts @a  # 3

Problem

I'm getting familiar with ruby send method, but for some reason, I can't do something like this ``` a = 4 a.send(:+=, 1) ``` For some reason this doesn't work. Then I tried something like ``` a.send(:=, a.send(:+, 1)) ``` But this doesn't work too. What is the proper way to fire plus equals through 'send'?

Original source