Project

General

Profile

Actions

Bug #20513

closed

the feature of kwargs in index assignment has been removed without due consideration of utility, compatibility, consistency and logic

Added by bughit (bug hit) about 2 months ago. Updated about 2 months ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:118090]

Description

See #20218

The ability to pass kwargs to index methods has been in ruby for a long time, probably from the inception of kwargs, so there's code that makes use of it. Other than the multiple assignment edge-case it's been working fine and is not conceptually unsound. kwargs allow for more variability in store/lookup operations via index methods, letting you control where/how something is stored/looked up.

this is from 2.6

module IndexTest
  @store = {}

  def self.store
    @store
  end

  def self.key(name, namespace: nil)
    name = "#{namespace}:#{name}" if namespace
    name
  end

  def self.[](name, namespace: nil)
    p [name, namespace]
    @store[key(name, namespace: namespace)]
  end

  def self.[]=(name, opts = {}, val)
    p [name, opts, val]
    @store[key(name, namespace: opts[:namespace])] = val
  end


end

IndexTest['foo'] = 1
p IndexTest['foo']
IndexTest['foo', namespace: 'bar'] = 2
p IndexTest['foo', namespace: 'bar']
p IndexTest.store

A reasonable breaking change would be for []= to have real kwargs, rather than the middle positional kwarg collector hash in the above example.

I am not arguing that breaking changes can't be introduced, but that a removal of a long-standing feature deserves more consideration and deliberation than the following:

I found that use of keyword arguments in multiple assignment is broken
Can we also prohibit keyword arguments ... ?
OK, prohibit keyword arguments


Related issues 1 (0 open1 closed)

Is duplicate of Ruby master - Bug #20218: aset/masgn/op_asgn with keyword argumentsClosedActions
Actions

Also available in: Atom PDF

Like1
Like0Like1Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like1Like0Like0Like1Like0Like0