Skip to content

Commit 38701a4

Browse files
committed
Remove deprecated support for to_set taking arguments
1 parent cb01b90 commit 38701a4

File tree

7 files changed

+22
-47
lines changed

7 files changed

+22
-47
lines changed

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ Note that each entry is kept to a minimum, see links for details.
1111

1212
Note: We're only listing outstanding class updates.
1313

14+
* Set
15+
16+
* A deprecated behavior, `Set#to_set`, `Range#to_set`, and
17+
`Enumerable#to_set` accepting arguments, was removed. [[Feature #21390]]
18+
1419
## Stdlib updates
1520

1621
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.
6166

6267
## JIT
6368

69+
[Feature #21390]: https://bugs.ruby-lang.org/issues/21390

benchmark/set.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,3 @@ benchmark:
259259
to_set_10: s1.to_set
260260
to_set_100: s2.to_set
261261
to_set_1000: s3.to_set
262-
to_set_arg_0: s0.to_set set_subclass
263-
to_set_arg_10: s1.to_set set_subclass
264-
to_set_arg_100: s2.to_set set_subclass
265-
to_set_arg_1000: s3.to_set set_subclass

lib/set/subclass_compatible.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,9 @@ def replace(enum)
6969
end
7070
end
7171

72-
def to_set(*args, &block)
73-
klass = if args.empty?
74-
Set
75-
else
76-
warn "passing arguments to Enumerable#to_set is deprecated", uplevel: 1
77-
args.shift
78-
end
79-
return self if instance_of?(Set) && klass == Set && block.nil? && args.empty?
80-
klass.new(self, *args, &block)
72+
def to_set(&block)
73+
return self if instance_of?(Set) && block.nil?
74+
Set.new(self, &block)
8175
end
8276

8377
def flatten_merge(set, seen = {}) # :nodoc:

prelude.rb

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,7 @@ def pp(*objs)
3030

3131
module Enumerable
3232
# Makes a set from the enumerable object with given arguments.
33-
# Passing arguments to this method is deprecated.
34-
def to_set(*args, &block)
35-
klass = if args.empty?
36-
Set
37-
else
38-
warn "passing arguments to Enumerable#to_set is deprecated", uplevel: 1
39-
args.shift
40-
end
41-
klass.new(self, *args, &block)
33+
def to_set(&block)
34+
Set.new(self, &block)
4235
end
4336
end

range.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,12 +1033,12 @@ range_to_a(VALUE range)
10331033
*
10341034
*/
10351035
static VALUE
1036-
range_to_set(int argc, VALUE *argv, VALUE range)
1036+
range_to_set(VALUE range)
10371037
{
10381038
if (NIL_P(RANGE_END(range))) {
10391039
rb_raise(rb_eRangeError, "cannot convert endless range to a set");
10401040
}
1041-
return rb_call_super(argc, argv);
1041+
return rb_call_super(0, NULL);
10421042
}
10431043

10441044
static VALUE
@@ -2868,7 +2868,7 @@ Init_Range(void)
28682868
rb_define_method(rb_cRange, "minmax", range_minmax, 0);
28692869
rb_define_method(rb_cRange, "size", range_size, 0);
28702870
rb_define_method(rb_cRange, "to_a", range_to_a, 0);
2871-
rb_define_method(rb_cRange, "to_set", range_to_set, -1);
2871+
rb_define_method(rb_cRange, "to_set", range_to_set, 0);
28722872
rb_define_method(rb_cRange, "entries", range_to_a, 0);
28732873
rb_define_method(rb_cRange, "to_s", range_to_s, 0);
28742874
rb_define_method(rb_cRange, "inspect", range_inspect, 0);

set.c

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -648,36 +648,22 @@ set_i_to_a(VALUE set)
648648

649649
/*
650650
* call-seq:
651-
* to_set(klass = Set, *args, &block) -> self or new_set
651+
* to_set(&block) -> self or new_set
652652
*
653-
* Without arguments, returns +self+ (for duck-typing in methods that
654-
* accept "set, or set-convertible" arguments).
653+
* Without a block, if +self+ is an instance of +Set+, returns +self+.
654+
* Otherwise, calls <tt>Set.new(self, &block)</tt>.
655655
*
656656
* A form with arguments is _deprecated_. It converts the set to another
657657
* with <tt>klass.new(self, *args, &block)</tt>.
658658
*/
659659
static VALUE
660-
set_i_to_set(int argc, VALUE *argv, VALUE set)
660+
set_i_to_set(VALUE set)
661661
{
662-
VALUE klass;
663-
664-
if (argc == 0) {
665-
klass = rb_cSet;
666-
argv = &set;
667-
argc = 1;
668-
}
669-
else {
670-
rb_warn_deprecated("passing arguments to Set#to_set", NULL);
671-
klass = argv[0];
672-
argv[0] = set;
673-
}
674-
675-
if (klass == rb_cSet && rb_obj_is_instance_of(set, rb_cSet) &&
676-
argc == 1 && !rb_block_given_p()) {
662+
if (rb_obj_is_instance_of(set, rb_cSet) && !rb_block_given_p()) {
677663
return set;
678664
}
679665

680-
return rb_funcall_passing_block(klass, id_new, argc, argv);
666+
return rb_funcall_passing_block(rb_cSet, id_new, 0, NULL);
681667
}
682668

683669
/*
@@ -2292,7 +2278,7 @@ Init_Set(void)
22922278
rb_define_method(rb_cSet, "superset?", set_i_superset, 1);
22932279
rb_define_alias(rb_cSet, ">=", "superset?");
22942280
rb_define_method(rb_cSet, "to_a", set_i_to_a, 0);
2295-
rb_define_method(rb_cSet, "to_set", set_i_to_set, -1);
2281+
rb_define_method(rb_cSet, "to_set", set_i_to_set, 0);
22962282

22972283
/* :nodoc: */
22982284
VALUE compat = rb_define_class_under(rb_cSet, "compatible", rb_cObject);

spec/ruby/core/enumerable/to_set_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
[1, 2, 3].to_set { |x| x * x }.should == Set[1, 4, 9]
1212
end
1313

14-
ruby_version_is "4.0" do
14+
ruby_version_is "4.0"..."4.1" do
1515
it "instantiates an object of provided as the first argument set class" do
1616
set = nil
1717
proc{set = [1, 2, 3].to_set(EnumerableSpecs::SetSubclass)}.should complain(/Enumerable#to_set/)

0 commit comments

Comments
 (0)