diff options
| author | Jeremy Evans <code@jeremyevans.net> | 2025-12-28 18:48:45 -0800 |
|---|---|---|
| committer | Jeremy Evans <code@jeremyevans.net> | 2025-12-29 14:54:41 +0900 |
| commit | 38701a4de83c72d855ce79f898526d5f079c96c5 (patch) | |
| tree | 1f4656c8f481047890919050bdfcf30d4c3b5a14 | |
| parent | cb01b9023ec2007c03bddc992416c33f2c59a0e1 (diff) | |
Remove deprecated support for to_set taking arguments
| -rw-r--r-- | NEWS.md | 6 | ||||
| -rw-r--r-- | benchmark/set.yml | 4 | ||||
| -rw-r--r-- | lib/set/subclass_compatible.rb | 12 | ||||
| -rw-r--r-- | prelude.rb | 11 | ||||
| -rw-r--r-- | range.c | 6 | ||||
| -rw-r--r-- | set.c | 28 | ||||
| -rw-r--r-- | spec/ruby/core/enumerable/to_set_spec.rb | 2 |
7 files changed, 22 insertions, 47 deletions
@@ -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 diff --git a/benchmark/set.yml b/benchmark/set.yml index 43217036e2..061509cb1f 100644 --- a/benchmark/set.yml +++ b/benchmark/set.yml @@ -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 diff --git a/lib/set/subclass_compatible.rb b/lib/set/subclass_compatible.rb index ab0aedc0e5..f43c34f6a2 100644 --- a/lib/set/subclass_compatible.rb +++ b/lib/set/subclass_compatible.rb @@ -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: diff --git a/prelude.rb b/prelude.rb index 36da381804..7b5a766898 100644 --- a/prelude.rb +++ b/prelude.rb @@ -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 @@ -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); @@ -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); diff --git a/spec/ruby/core/enumerable/to_set_spec.rb b/spec/ruby/core/enumerable/to_set_spec.rb index e1fcd3a20d..91499aeb5b 100644 --- a/spec/ruby/core/enumerable/to_set_spec.rb +++ b/spec/ruby/core/enumerable/to_set_spec.rb @@ -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/) |
