From: "hmdne (hmdne -)" Date: 2022-02-27T03:14:12+00:00 Subject: [ruby-core:107751] [Ruby master Feature#18603] Allow syntax like obj.method(arg)=value Issue #18603 has been reported by hmdne (hmdne -). ---------------------------------------- Feature #18603: Allow syntax like obj.method(arg)=value https://bugs.ruby-lang.org/issues/18603 * 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: