From: alxtskrnk@... Date: 2015-12-04T23:14:45+00:00 Subject: [ruby-core:71838] [Ruby trunk - Bug #11771] unable to pass keyargs to []= Issue #11771 has been updated by bug hit. Eric Wong wrote: > Affects back to 2.0 (when keyword args were introduced), > so this doesn't seem to be an optimization bug introduced in 2.1/2.2 > > I'm actually not sure about the specs and if there's some special case > for kwargs interacting with aref/aset... > The problem here is that the []= syntax compiled into a method dispatch where positional value arg is passed last, after keyargs, something you can't even do in ruby. you can simulate the bug with a plain method: ```ruby def foo(key, val, option: nil) end foo(:key, 1, option: 1) # ok foo(:key, {option: 1}, 1) # wrong number of arguments (3 for 2) ``` ---------------------------------------- Bug #11771: unable to pass keyargs to []= https://bugs.ruby-lang.org/issues/11771#change-55242 * Author: bug hit * Status: Open * Priority: Normal * Assignee: * ruby -v: 2.2.3 * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN ---------------------------------------- ```ruby module Foo def self.[]=(key, val, option: nil) end end Foo[:key] = 1 # ok Foo[:key, option: 1] = 1 # wrong number of arguments (3 for 2) ``` if you declare the []= params using * ```ruby module Bar def self.[]=(*args) p args end end Bar[:key, option: 1] = 1 # args: [:key, {:option=>1}, 1] ``` the args end up [:key, {:option=>1}, 1] which seems wrong since the keyargs hash is supposed to be last -- https://bugs.ruby-lang.org/