Issue #11939 has been updated by Sumit Mahamuni.


According to ruby conventions shouldn't that be 


var.some_method!(some_args) if some_condition. 


Why do you need new feature?

----------------------------------------
Feature #11939: Syntax sugar to apply a method replace a variable
https://bugs.ruby-lang.org/issues/11939#change-55949

* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
There is frequent use case to modify the value of a variable and keep it referred to by the same variable name. When method chaining cannot be done (for example, when the method is conditionally called), the same variable name would have to be repeated:

~~~ruby
var = ...
var = var.some_method(some_args) if some_condition
var = ...
...
~~~

I would like to propose a syntax sugar for this kind of situation. I have two options in mind.

(1) `=.`

~~~ruby
var = ...
var =.some_method(some_args) if some_condition
var = ...
...
~~~

(2) `.=`

~~~ruby
var = ...
var .= some_method(some_args) if some_condition
var = ...
...
~~~

Notation (2) seems to be in line with syntax sugar like `+=`, but option (1) has the advantage that the period comes together with the method name.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>