Project

General

Profile

Actions

Feature #21390

closed

Deprecate passing arguments to Set#to_set and Enumerable#to_set

Added by jeremyevans0 (Jeremy Evans) 5 days ago. Updated about 20 hours ago.

Status:
Closed
Target version:
-
[ruby-core:122356]

Description

Array#to_a, Hash#to_h, Enumerable#to_a, and Enumerable#to_h do not allow you to specify subclasses. This has undesired behavior when passing non-Set subclasses. All of these are currently allowed, and none make sense:

enum = [1,2,3].to_enum

enum.to_set(Hash)
enum.to_set(Struct.new("A", :a))
enum.to_set(ArgumentError)
enum.to_set(Thread){}

Users who want to create instances of a subclass of Set from an enumerable should pass the enumerable to SetSubclass.new instead of using to_set, similar to how they would have to handle subclasses of Array or Hash.

I've submitted a pull request that implements this: https://github.com/ruby/ruby/pull/13489

With the pull request, block arguments are still allowed (no warning). Positional and keyword argument use results in a deprecation warning.

I would like to deprecate this in Ruby 3.5 (next feature release), and remove it in Ruby 3.6 (following feature release).

Updated by nobu (Nobuyoshi Nakada) 1 day ago

  • Status changed from Open to Assigned
  • Assignee set to knu (Akinori MUSHA)

Updated by knu (Akinori MUSHA) about 24 hours ago ยท Edited

I can agree with this. As it turned out, subclassing the Set class did not become very common, so I think it's fine to deprecate this feature now.

Updated by jeremyevans0 (Jeremy Evans) about 20 hours ago

  • Status changed from Assigned to Closed
Actions

Also available in: Atom PDF

Like1
Like0Like0Like0