aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShugo Maeda <shugo@ruby-lang.org>2023-07-14 15:13:14 +0900
committerShugo Maeda <shugo.maeda@gmail.com>2023-07-31 17:23:17 +0900
commita542512b7c394847a488e9b94d9defebe26003ce (patch)
tree287657083fba9728d52407d0d224f3a0497cfebc
parentcfd7729ce7a31c8b6ec5dd0e99c67b2932de4732 (diff)
downloadruby-a542512b7c394847a488e9b94d9defebe26003ce.tar.gz
Add Refinement#target and deprecate Refinement#refined_class
[Feature #19714]
-rw-r--r--NEWS.md5
-rw-r--r--eval.c20
-rw-r--r--test/ruby/test_refinement.rb4
3 files changed, 25 insertions, 4 deletions
diff --git a/NEWS.md b/NEWS.md
index f3bba5336c..d00f60ca77 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -56,6 +56,11 @@ Note: We're only listing outstanding class updates.
for long running applications. The actual optimizations performed are entirely
implementation specific and may change in the future without notice. [[Feature #18885]
+* Refinement
+
+ * Add Refinement#target as an alternative of Refinement#refined_class.
+ Refinement#refined_class is deprecated and will be removed in Ruby 3.4. [[Feature #19714]]
+
## Stdlib updates
The following default gems are updated.
diff --git a/eval.c b/eval.c
index efac69735b..844c537cc4 100644
--- a/eval.c
+++ b/eval.c
@@ -1346,9 +1346,9 @@ rb_using_module(const rb_cref_t *cref, VALUE module)
/*
* call-seq:
- * refined_class -> class
+ * target -> class
*
- * Return the class refined by the receiver.
+ * Return the class or module refined by the receiver.
*/
VALUE
rb_refinement_module_get_refined_class(VALUE module)
@@ -1359,6 +1359,19 @@ rb_refinement_module_get_refined_class(VALUE module)
return rb_attr_get(module, id_refined_class);
}
+/*
+ * call-seq:
+ * refined_class -> class
+ *
+ * Return the class refined by the receiver.
+ */
+static VALUE
+rb_refinement_refined_class(VALUE module)
+{
+ rb_warn_deprecated_to_remove("3.4", "Refinement#refined_class", "Refinement#target");
+ return rb_refinement_module_get_refined_class(module);
+}
+
static void
add_activated_refinement(VALUE activated_refinements,
VALUE klass, VALUE refinement)
@@ -2067,7 +2080,8 @@ Init_eval(void)
rb_mod_s_used_refinements, 0);
rb_undef_method(rb_cClass, "refine");
rb_define_private_method(rb_cRefinement, "import_methods", refinement_import_methods, -1);
- rb_define_method(rb_cRefinement, "refined_class", rb_refinement_module_get_refined_class, 0);
+ rb_define_method(rb_cRefinement, "target", rb_refinement_module_get_refined_class, 0);
+ rb_define_method(rb_cRefinement, "refined_class", rb_refinement_refined_class, 0);
rb_undef_method(rb_cRefinement, "append_features");
rb_undef_method(rb_cRefinement, "prepend_features");
rb_undef_method(rb_cRefinement, "extend_object");
diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb
index 7cddfce6bd..5d4d6e6520 100644
--- a/test/ruby/test_refinement.rb
+++ b/test/ruby/test_refinement.rb
@@ -1798,7 +1798,7 @@ class TestRefinement < Test::Unit::TestCase
assert_equal([int_refinement, str_refinement], m.refinements)
end
- def test_refined_class
+ def test_target
refinements = Module.new {
refine Integer do
end
@@ -1806,7 +1806,9 @@ class TestRefinement < Test::Unit::TestCase
refine String do
end
}.refinements
+ assert_equal(Integer, refinements[0].target)
assert_equal(Integer, refinements[0].refined_class)
+ assert_equal(String, refinements[1].target)
assert_equal(String, refinements[1].refined_class)
end