diff options
author | Shugo Maeda <shugo@ruby-lang.org> | 2021-10-21 16:21:08 +0900 |
---|---|---|
committer | Shugo Maeda <shugo@ruby-lang.org> | 2021-10-21 16:31:54 +0900 |
commit | 6606597109bdb535a150606323ce3d8f5750e1f6 (patch) | |
tree | 153eac378825ad9b17be9e8ae10d80572641f2c5 /test | |
parent | 7185c00fcc330db8951b684f548ba3d10983bb92 (diff) |
Deprecate include/prepend in refinements and add Refinement#import_methods instead
Refinement#import_methods imports methods from modules.
Unlike Module#include, it copies methods and adds them into the refinement,
so the refinement is activated in the imported methods.
[Bug #17429] [ruby-core:101639]
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_refinement.rb | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb index 96baab03ee..fa9f5532d5 100644 --- a/test/ruby/test_refinement.rb +++ b/test/ruby/test_refinement.rb @@ -2590,6 +2590,71 @@ class TestRefinement < Test::Unit::TestCase assert_equal([refinement], as, "[ruby-core:86949] [Bug #14744]") end + module TestImport + class A + def foo + "original" + end + end + + module B + BAR = "bar" + + def bar + "#{foo}:#{BAR}" + end + end + + module C + refine A do + import_methods B + + def foo + "refined" + end + end + end + + module D + refine A do + include B + + def foo + "refined" + end + end + end + + module UsingC + using C + + def self.call_bar + A.new.bar + end + end + + module UsingD + using D + + def self.call_bar + A.new.bar + end + end + end + + def test_import_methods + assert_equal("refined:bar", TestImport::UsingC.call_bar) + assert_equal("original:bar", TestImport::UsingD.call_bar) + + assert_raise(ArgumentError) do + Module.new do + refine Integer do + import_methods Enumerable + end + end + end + end + private def eval_using(mod, s) |