[#107430] [Ruby master Feature#18566] Merge `io-wait` gem into core IO — "byroot (Jean Boussier)" <noreply@...>
Issue #18566 has been reported by byroot (Jean Boussier).
22 messages
2022/02/02
[ruby-core:107757] [Ruby master Feature#18603] Allow syntax like obj.method(arg)=value
From:
"Eregon (Benoit Daloze)" <noreply@...>
Date:
2022-02-27 17:04:17 UTC
List:
ruby-core #107757
Issue #18603 has been updated by Eregon (Benoit Daloze).
IMHO way too complicated and `[]=` seems good enough for this use case.
Also it would be very confusing as the similar and existing syntax `def obj.method(arg) = value` means something completely different.
----------------------------------------
Feature #18603: Allow syntax like obj.method(arg)=value
https://bugs.ruby-lang.org/issues/18603#change-96682
* Author: hmdne (hmdne -)
* Status: Open
* Priority: Normal
----------------------------------------
I propose here to allow a syntax like:
```ruby
obj.method(arg) = value
```
It would be translated to the following:
```ruby
obj.__send__(:method=, arg, value)
```
The lack of this syntax kind of limits the ability to design DSLs in Ruby in my opinion. I don't think this would bring any conflicts with existing parser rules.
My proposal would be to put the value at the last argument, akin to how `[]=` works. So, for example this code would work:
```ruby
module Indexable
def dig=(*path, last, value)
if path.empty?
self[last] = value
else
first = path.shift
self[first]&.dig(*path, last) = value
end
end
end
Hash.include Indexable
Array.include Indexable
```
The kwargs may be supported similarly to how they work on `[]=`, ie. becoming a penultimate Hash argument. While maybe not perfect, it is consistent with how `[]=` works and I imagine most usecases won't require kwargs.
--
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>