Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Bug #20253] All the way down to Ruby 1.9, `Proc`, `Method`, `UnboundMethod` and `Binding` always had their own specific clone and dup routine. This caused various discrepancies with how other objects behave on `dup` and `clone. [Bug #20250], [Bug #20253]. This commit get rid of `CLONESETUP` and use the the same codepath as all other types, so ensure consistency. NB: It's still not accepting the `freeze` keyword argument on `clone`. Co-Authored-By: Étienne Barrié <etienne.barrie@gmail.com>
- Loading branch information
1 parent
c04782c
commit de1a586
Showing
15 changed files
with
228 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
require_relative '../../spec_helper' | ||
require_relative 'fixtures/classes' | ||
require_relative 'shared/dup' | ||
|
||
describe "Method#clone" do | ||
it "returns a copy of the method" do | ||
m1 = MethodSpecs::Methods.new.method(:foo) | ||
m2 = m1.clone | ||
it_behaves_like :method_dup, :clone | ||
|
||
m1.should == m2 | ||
m1.should_not equal(m2) | ||
|
||
m1.call.should == m2.call | ||
it "preserves frozen status" do | ||
method = Object.new.method(:method) | ||
method.freeze | ||
method.frozen?.should == true | ||
method.clone.frozen?.should == true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require_relative '../../spec_helper' | ||
require_relative 'shared/dup' | ||
|
||
describe "Method#dup" do | ||
ruby_version_is "3.4" do | ||
it_behaves_like :method_dup, :dup | ||
|
||
it "resets frozen status" do | ||
method = Object.new.method(:method) | ||
method.freeze | ||
method.frozen?.should == true | ||
method.dup.frozen?.should == false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
describe :method_dup, shared: true do | ||
it "returns a copy of self" do | ||
a = Object.new.method(:method) | ||
b = a.send(@method) | ||
|
||
a.should == b | ||
a.should_not equal(b) | ||
end | ||
|
||
ruby_version_is "3.4" do | ||
it "copies instance variables" do | ||
method = Object.new.method(:method) | ||
method.instance_variable_set(:@ivar, 1) | ||
cl = method.send(@method) | ||
cl.instance_variables.should == [:@ivar] | ||
end | ||
|
||
it "copies the finalizer" do | ||
code = <<-RUBY | ||
obj = Object.new.method(:method) | ||
ObjectSpace.define_finalizer(obj, Proc.new { STDOUT.write "finalized\n" }) | ||
obj.clone | ||
exit 0 | ||
RUBY | ||
|
||
ruby_exe(code).lines.sort.should == ["finalized\n", "finalized\n"] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
require_relative '../../spec_helper' | ||
require_relative 'fixtures/classes' | ||
require_relative 'shared/dup' | ||
|
||
describe "UnboundMethod#clone" do | ||
it "returns a copy of the UnboundMethod" do | ||
um1 = UnboundMethodSpecs::Methods.instance_method(:foo) | ||
um2 = um1.clone | ||
it_behaves_like :unboundmethod_dup, :clone | ||
|
||
(um1 == um2).should == true | ||
um1.bind(UnboundMethodSpecs::Methods.new).call.should == um2.bind(UnboundMethodSpecs::Methods.new).call | ||
it "preserves frozen status" do | ||
method = Class.instance_method(:instance_method) | ||
method.freeze | ||
method.frozen?.should == true | ||
method.clone.frozen?.should == true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require_relative '../../spec_helper' | ||
require_relative 'shared/dup' | ||
|
||
describe "UnboundMethod#dup" do | ||
ruby_version_is "3.4" do | ||
it_behaves_like :unboundmethod_dup, :dup | ||
|
||
it "resets frozen status" do | ||
method = Class.instance_method(:instance_method) | ||
method.freeze | ||
method.frozen?.should == true | ||
method.dup.frozen?.should == false | ||
end | ||
end | ||
end |
Oops, something went wrong.