mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Add refinements support to method/instance_method.
[Fix GH-2034] From: manga_osyo <manga.osyo@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66935 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2210709b79
commit
2a4c87dc31
5 changed files with 117 additions and 15 deletions
|
@ -526,20 +526,78 @@ describe "Module#refine" do
|
|||
result.should == "hello from refinement"
|
||||
end
|
||||
|
||||
it "is not honored by Kernel#method" do
|
||||
klass = Class.new
|
||||
refinement = Module.new do
|
||||
refine klass do
|
||||
def foo; end
|
||||
ruby_version_is "" ... "2.7" do
|
||||
it "is not honored by Kernel#method" do
|
||||
klass = Class.new
|
||||
refinement = Module.new do
|
||||
refine klass do
|
||||
def foo; end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-> {
|
||||
-> {
|
||||
Module.new do
|
||||
using refinement
|
||||
klass.new.method(:foo)
|
||||
end
|
||||
}.should raise_error(NameError, /undefined method `foo'/)
|
||||
end
|
||||
end
|
||||
|
||||
ruby_version_is "2.7" do
|
||||
it "is honored by Kernel#method" do
|
||||
klass = Class.new
|
||||
refinement = Module.new do
|
||||
refine klass do
|
||||
def foo; end
|
||||
end
|
||||
end
|
||||
|
||||
result = nil
|
||||
Module.new do
|
||||
using refinement
|
||||
klass.new.method(:foo)
|
||||
result = klass.new.method(:foo).class
|
||||
end
|
||||
}.should raise_error(NameError, /undefined method `foo'/)
|
||||
|
||||
result.should == Method
|
||||
end
|
||||
end
|
||||
|
||||
ruby_version_is "" ... "2.7" do
|
||||
it "is not honored by Kernel#instance_method" do
|
||||
klass = Class.new
|
||||
refinement = Module.new do
|
||||
refine klass do
|
||||
def foo; end
|
||||
end
|
||||
end
|
||||
|
||||
-> {
|
||||
Module.new do
|
||||
using refinement
|
||||
klass.instance_method(:foo)
|
||||
end
|
||||
}.should raise_error(NameError, /undefined method `foo'/)
|
||||
end
|
||||
end
|
||||
|
||||
ruby_version_is "2.7" do
|
||||
it "is honored by Kernel#method" do
|
||||
klass = Class.new
|
||||
refinement = Module.new do
|
||||
refine klass do
|
||||
def foo; end
|
||||
end
|
||||
end
|
||||
|
||||
result = nil
|
||||
Module.new do
|
||||
using refinement
|
||||
result = klass.instance_method(:foo).class
|
||||
end
|
||||
|
||||
result.should == UnboundMethod
|
||||
end
|
||||
end
|
||||
|
||||
ruby_version_is "" ... "2.6" do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue