Remove deprecated support for to_set taking arguments

This commit is contained in:
Jeremy Evans committed 2025-12-29 14:54:41 +09:00
1 parent cb01b9023e
commit 38701a4de8
7 files changed
+22 -47
Notes: git 2025-12-29 05:55:09 +00:00

No files matched your search

+6
View File
@@ -11,6 +11,11 @@ Note that each entry is kept to a minimum, see links for details.
Note: We're only listing outstanding class updates.
* Set
* A deprecated behavior, `Set#to_set`, `Range#to_set`, and
`Enumerable#to_set` accepting arguments, was removed. [[Feature #21390]]
## Stdlib updates
We only list stdlib changes that are notable feature changes.
@@ -61,3 +66,4 @@ A lot of work has gone into making Ractors more stable, performant, and usable.
## JIT
[Feature #21390]: https://bugs.ruby-lang.org/issues/21390
-4
View File
@@ -259,7 +259,3 @@ benchmark:
to_set_10: s1.to_set
to_set_100: s2.to_set
to_set_1000: s3.to_set
to_set_arg_0: s0.to_set set_subclass
to_set_arg_10: s1.to_set set_subclass
to_set_arg_100: s2.to_set set_subclass
to_set_arg_1000: s3.to_set set_subclass
+3 -9
View File
@@ -69,15 +69,9 @@ class Set
end
end
def to_set(*args, &block)
klass = if args.empty?
Set
else
warn "passing arguments to Enumerable#to_set is deprecated", uplevel: 1
args.shift
end
return self if instance_of?(Set) && klass == Set && block.nil? && args.empty?
klass.new(self, *args, &block)
def to_set(&block)
return self if instance_of?(Set) && block.nil?
Set.new(self, &block)
end
def flatten_merge(set, seen = {}) # :nodoc:
+2 -9
View File
@@ -30,14 +30,7 @@ end
module Enumerable
# Makes a set from the enumerable object with given arguments.
# Passing arguments to this method is deprecated.
def to_set(*args, &block)
klass = if args.empty?
Set
else
warn "passing arguments to Enumerable#to_set is deprecated", uplevel: 1
args.shift
end
klass.new(self, *args, &block)
def to_set(&block)
Set.new(self, &block)
end
end
+3 -3
View File
@@ -1033,12 +1033,12 @@ range_to_a(VALUE range)
*
*/
static VALUE
range_to_set(int argc, VALUE *argv, VALUE range)
range_to_set(VALUE range)
{
if (NIL_P(RANGE_END(range))) {
rb_raise(rb_eRangeError, "cannot convert endless range to a set");
}
return rb_call_super(argc, argv);
return rb_call_super(0, NULL);
}
static VALUE
@@ -2868,7 +2868,7 @@ Init_Range(void)
rb_define_method(rb_cRange, "minmax", range_minmax, 0);
rb_define_method(rb_cRange, "size", range_size, 0);
rb_define_method(rb_cRange, "to_a", range_to_a, 0);
rb_define_method(rb_cRange, "to_set", range_to_set, -1);
rb_define_method(rb_cRange, "to_set", range_to_set, 0);
rb_define_method(rb_cRange, "entries", range_to_a, 0);
rb_define_method(rb_cRange, "to_s", range_to_s, 0);
rb_define_method(rb_cRange, "inspect", range_inspect, 0);
+7 -21
View File
@@ -648,36 +648,22 @@ set_i_to_a(VALUE set)
/*
* call-seq:
* to_set(klass = Set, *args, &block) -> self or new_set
* to_set(&block) -> self or new_set
*
* Without arguments, returns +self+ (for duck-typing in methods that
* accept "set, or set-convertible" arguments).
* Without a block, if +self+ is an instance of +Set+, returns +self+.
* Otherwise, calls <tt>Set.new(self, &block)</tt>.
*
* A form with arguments is _deprecated_. It converts the set to another
* with <tt>klass.new(self, *args, &block)</tt>.
*/
static VALUE
set_i_to_set(int argc, VALUE *argv, VALUE set)
set_i_to_set(VALUE set)
{
VALUE klass;
if (argc == 0) {
klass = rb_cSet;
argv = &set;
argc = 1;
}
else {
rb_warn_deprecated("passing arguments to Set#to_set", NULL);
klass = argv[0];
argv[0] = set;
}
if (klass == rb_cSet && rb_obj_is_instance_of(set, rb_cSet) &&
argc == 1 && !rb_block_given_p()) {
if (rb_obj_is_instance_of(set, rb_cSet) && !rb_block_given_p()) {
return set;
}
return rb_funcall_passing_block(klass, id_new, argc, argv);
return rb_funcall_passing_block(rb_cSet, id_new, 0, NULL);
}
/*
@@ -2292,7 +2278,7 @@ Init_Set(void)
rb_define_method(rb_cSet, "superset?", set_i_superset, 1);
rb_define_alias(rb_cSet, ">=", "superset?");
rb_define_method(rb_cSet, "to_a", set_i_to_a, 0);
rb_define_method(rb_cSet, "to_set", set_i_to_set, -1);
rb_define_method(rb_cSet, "to_set", set_i_to_set, 0);
/* :nodoc: */
VALUE compat = rb_define_class_under(rb_cSet, "compatible", rb_cObject);
+1 -1
View File
@@ -11,7 +11,7 @@ describe "Enumerable#to_set" do
[1, 2, 3].to_set { |x| x * x }.should == Set[1, 4, 9]
end
ruby_version_is "4.0" do
ruby_version_is "4.0"..."4.1" do
it "instantiates an object of provided as the first argument set class" do
set = nil
proc{set = [1, 2, 3].to_set(EnumerableSpecs::SetSubclass)}.should complain(/Enumerable#to_set/)