[ruby-core:122427] [Ruby Feature#21390] Deprecate passing arguments to Set#to_set and Enumerable#to_set
From:
"nobu (Nobuyoshi Nakada) via ruby-core" <ruby-core@...>
Date:
2025-06-05 05:54:19 UTC
List:
ruby-core #122427
Issue #21390 has been updated by nobu (Nobuyoshi Nakada).
Status changed from Open to Assigned
Assignee set to knu (Akinori MUSHA)
----------------------------------------
Feature #21390: Deprecate passing arguments to Set#to_set and Enumerable#to_set
https://bugs.ruby-lang.org/issues/21390#change-113607
* Author: jeremyevans0 (Jeremy Evans)
* Status: Assigned
* Assignee: knu (Akinori MUSHA)
----------------------------------------
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:
```ruby
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).
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/