Skip to content

Commit a542512

Browse files
committed
Add Refinement#target and deprecate Refinement#refined_class
[Feature #19714]
1 parent cfd7729 commit a542512

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ Note: We're only listing outstanding class updates.
5656
for long running applications. The actual optimizations performed are entirely
5757
implementation specific and may change in the future without notice. [[Feature #18885]
5858

59+
* Refinement
60+
61+
* Add Refinement#target as an alternative of Refinement#refined_class.
62+
Refinement#refined_class is deprecated and will be removed in Ruby 3.4. [[Feature #19714]]
63+
5964
## Stdlib updates
6065

6166
The following default gems are updated.

eval.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,9 +1346,9 @@ rb_using_module(const rb_cref_t *cref, VALUE module)
13461346

13471347
/*
13481348
* call-seq:
1349-
* refined_class -> class
1349+
* target -> class
13501350
*
1351-
* Return the class refined by the receiver.
1351+
* Return the class or module refined by the receiver.
13521352
*/
13531353
VALUE
13541354
rb_refinement_module_get_refined_class(VALUE module)
@@ -1359,6 +1359,19 @@ rb_refinement_module_get_refined_class(VALUE module)
13591359
return rb_attr_get(module, id_refined_class);
13601360
}
13611361

1362+
/*
1363+
* call-seq:
1364+
* refined_class -> class
1365+
*
1366+
* Return the class refined by the receiver.
1367+
*/
1368+
static VALUE
1369+
rb_refinement_refined_class(VALUE module)
1370+
{
1371+
rb_warn_deprecated_to_remove("3.4", "Refinement#refined_class", "Refinement#target");
1372+
return rb_refinement_module_get_refined_class(module);
1373+
}
1374+
13621375
static void
13631376
add_activated_refinement(VALUE activated_refinements,
13641377
VALUE klass, VALUE refinement)
@@ -2067,7 +2080,8 @@ Init_eval(void)
20672080
rb_mod_s_used_refinements, 0);
20682081
rb_undef_method(rb_cClass, "refine");
20692082
rb_define_private_method(rb_cRefinement, "import_methods", refinement_import_methods, -1);
2070-
rb_define_method(rb_cRefinement, "refined_class", rb_refinement_module_get_refined_class, 0);
2083+
rb_define_method(rb_cRefinement, "target", rb_refinement_module_get_refined_class, 0);
2084+
rb_define_method(rb_cRefinement, "refined_class", rb_refinement_refined_class, 0);
20712085
rb_undef_method(rb_cRefinement, "append_features");
20722086
rb_undef_method(rb_cRefinement, "prepend_features");
20732087
rb_undef_method(rb_cRefinement, "extend_object");

test/ruby/test_refinement.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1798,15 +1798,17 @@ def test_refinements
17981798
assert_equal([int_refinement, str_refinement], m.refinements)
17991799
end
18001800

1801-
def test_refined_class
1801+
def test_target
18021802
refinements = Module.new {
18031803
refine Integer do
18041804
end
18051805

18061806
refine String do
18071807
end
18081808
}.refinements
1809+
assert_equal(Integer, refinements[0].target)
18091810
assert_equal(Integer, refinements[0].refined_class)
1811+
assert_equal(String, refinements[1].target)
18101812
assert_equal(String, refinements[1].refined_class)
18111813
end
18121814

0 commit comments

Comments
 (0)