From: "Eregon (Benoit Daloze)" Date: 2022-02-27T17:04:17+00:00 Subject: [ruby-core:107757] [Ruby master Feature#18603] Allow syntax like obj.method(arg)=value 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: