зеркало из https://github.com/github/ruby.git
Remove Refinement#include and Refinement#prepend
This commit is contained in:
Родитель
39bc5de833
Коммит
69f03c864e
4
eval.c
4
eval.c
|
@ -1129,7 +1129,7 @@ rb_mod_include(int argc, VALUE *argv, VALUE module)
|
|||
CONST_ID(id_included, "included");
|
||||
|
||||
if (FL_TEST(module, RMODULE_IS_REFINEMENT)) {
|
||||
rb_warn_deprecated_to_remove_at(3.2, "Refinement#include", NULL);
|
||||
rb_raise(rb_eTypeError, "Refinement#include has been removed");
|
||||
}
|
||||
|
||||
rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
|
||||
|
@ -1179,7 +1179,7 @@ rb_mod_prepend(int argc, VALUE *argv, VALUE module)
|
|||
ID id_prepend_features, id_prepended;
|
||||
|
||||
if (FL_TEST(module, RMODULE_IS_REFINEMENT)) {
|
||||
rb_warn_deprecated_to_remove_at(3.2, "Refinement#prepend", NULL);
|
||||
rb_raise(rb_eTypeError, "Refinement#prepend has been removed");
|
||||
}
|
||||
|
||||
CONST_ID(id_prepend_features, "prepend_features");
|
||||
|
|
|
@ -243,28 +243,30 @@ describe "Module#refine" do
|
|||
result.should == "foo from singleton class"
|
||||
end
|
||||
|
||||
it "looks in the included modules for builtin methods" do
|
||||
result = ruby_exe(<<-RUBY)
|
||||
a = Module.new do
|
||||
def /(other) quo(other) end
|
||||
end
|
||||
|
||||
refinement = Module.new do
|
||||
refine Integer do
|
||||
include a
|
||||
ruby_version_is ""..."3.2" do
|
||||
it "looks in the included modules for builtin methods" do
|
||||
result = ruby_exe(<<-RUBY)
|
||||
a = Module.new do
|
||||
def /(other) quo(other) end
|
||||
end
|
||||
end
|
||||
|
||||
result = nil
|
||||
Module.new do
|
||||
using refinement
|
||||
result = 1 / 2
|
||||
end
|
||||
refinement = Module.new do
|
||||
refine Integer do
|
||||
include a
|
||||
end
|
||||
end
|
||||
|
||||
print result.class
|
||||
RUBY
|
||||
result = nil
|
||||
Module.new do
|
||||
using refinement
|
||||
result = 1 / 2
|
||||
end
|
||||
|
||||
result.should == 'Rational'
|
||||
print result.class
|
||||
RUBY
|
||||
|
||||
result.should == 'Rational'
|
||||
end
|
||||
end
|
||||
|
||||
it "looks in later included modules of the refined module first" do
|
||||
|
|
|
@ -754,134 +754,30 @@ class TestRefinement < Test::Unit::TestCase
|
|||
$VERBOSE = verbose
|
||||
end
|
||||
|
||||
module IncludeIntoRefinement
|
||||
class C
|
||||
def bar
|
||||
return "C#bar"
|
||||
end
|
||||
|
||||
def baz
|
||||
return "C#baz"
|
||||
end
|
||||
end
|
||||
|
||||
module Mixin
|
||||
def foo
|
||||
return "Mixin#foo"
|
||||
end
|
||||
|
||||
def bar
|
||||
return super << " Mixin#bar"
|
||||
end
|
||||
|
||||
def baz
|
||||
return super << " Mixin#baz"
|
||||
end
|
||||
end
|
||||
|
||||
module M
|
||||
refine C do
|
||||
TestRefinement.suppress_verbose do
|
||||
include Mixin
|
||||
end
|
||||
|
||||
def baz
|
||||
return super << " M#baz"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
eval <<-EOF, Sandbox::BINDING
|
||||
using TestRefinement::IncludeIntoRefinement::M
|
||||
|
||||
module TestRefinement::IncludeIntoRefinement::User
|
||||
def self.invoke_foo_on(x)
|
||||
x.foo
|
||||
end
|
||||
|
||||
def self.invoke_bar_on(x)
|
||||
x.bar
|
||||
end
|
||||
|
||||
def self.invoke_baz_on(x)
|
||||
x.baz
|
||||
end
|
||||
end
|
||||
EOF
|
||||
|
||||
def test_include_into_refinement
|
||||
x = IncludeIntoRefinement::C.new
|
||||
assert_equal("Mixin#foo", IncludeIntoRefinement::User.invoke_foo_on(x))
|
||||
assert_equal("C#bar Mixin#bar",
|
||||
IncludeIntoRefinement::User.invoke_bar_on(x))
|
||||
assert_equal("C#baz Mixin#baz M#baz",
|
||||
IncludeIntoRefinement::User.invoke_baz_on(x))
|
||||
end
|
||||
assert_raise(TypeError) do
|
||||
c = Class.new
|
||||
mixin = Module.new
|
||||
|
||||
module PrependIntoRefinement
|
||||
class C
|
||||
def bar
|
||||
return "C#bar"
|
||||
end
|
||||
|
||||
def baz
|
||||
return "C#baz"
|
||||
end
|
||||
end
|
||||
|
||||
module Mixin
|
||||
def foo
|
||||
return "Mixin#foo"
|
||||
end
|
||||
|
||||
def bar
|
||||
return super << " Mixin#bar"
|
||||
end
|
||||
|
||||
def baz
|
||||
return super << " Mixin#baz"
|
||||
end
|
||||
end
|
||||
|
||||
module M
|
||||
refine C do
|
||||
TestRefinement.suppress_verbose do
|
||||
prepend Mixin
|
||||
end
|
||||
|
||||
def baz
|
||||
return super << " M#baz"
|
||||
Module.new do
|
||||
refine c do
|
||||
include mixin
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
eval <<-EOF, Sandbox::BINDING
|
||||
using TestRefinement::PrependIntoRefinement::M
|
||||
|
||||
module TestRefinement::PrependIntoRefinement::User
|
||||
def self.invoke_foo_on(x)
|
||||
x.foo
|
||||
end
|
||||
|
||||
def self.invoke_bar_on(x)
|
||||
x.bar
|
||||
end
|
||||
|
||||
def self.invoke_baz_on(x)
|
||||
x.baz
|
||||
end
|
||||
end
|
||||
EOF
|
||||
|
||||
def test_prepend_into_refinement
|
||||
x = PrependIntoRefinement::C.new
|
||||
assert_equal("Mixin#foo", PrependIntoRefinement::User.invoke_foo_on(x))
|
||||
assert_equal("C#bar Mixin#bar",
|
||||
PrependIntoRefinement::User.invoke_bar_on(x))
|
||||
assert_equal("C#baz M#baz Mixin#baz",
|
||||
PrependIntoRefinement::User.invoke_baz_on(x))
|
||||
assert_raise(TypeError) do
|
||||
c = Class.new
|
||||
mixin = Module.new
|
||||
|
||||
Module.new do
|
||||
refine c do
|
||||
prepend mixin
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
PrependAfterRefine_CODE = <<-EOC
|
||||
|
@ -2626,18 +2522,6 @@ class TestRefinement < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
module D
|
||||
refine A do
|
||||
TestRefinement.suppress_verbose do
|
||||
include B
|
||||
end
|
||||
|
||||
def foo
|
||||
"refined"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module UsingC
|
||||
using C
|
||||
|
||||
|
@ -2645,19 +2529,10 @@ class TestRefinement < Test::Unit::TestCase
|
|||
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
|
||||
|
|
Загрузка…
Ссылка в новой задаче