Issue #15616 has been updated by duerst (Martin Drst).

Status changed from Open to Rejected

Yes. It's a matter of precedence. The "Pickaxe" book describes it as

> Single terms in an expression may be any of the following:
> 
> [some cases omitted]
> 
> - Method invocation

That means that in ```+foo.gsub!("bar", "car")```, the `.` of method invocation has higher precedence than the `+`, and so you need to use parentheses if you want to change the order of evaluation.

----------------------------------------
Bug #15616: Chained destructive methods fail when using +@ to unfreeze a frozen string
https://bugs.ruby-lang.org/issues/15616#change-76883

* Author: cianooooo (Cian O)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.6.1
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Using the +@ syntax to unfreeze a string does not work when chaining destructive methods

Consider the following;
``` ruby
foo = "bar".freeze
+foo.gsub!("bar", "car")
```

This raises;
``` ruby
FrozenError: can't modify frozen String
```

However, I would have expected this to work since +@ should return a duplicated mutable string.



-- 
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>