1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Implement Proc#== and #eql?

Previously, these were not implemented, and Object#== and #eql?
were used.  This tries to check the proc internals to make sure
that procs created from separate blocks are treated as not equal,
but procs created from the same block are treated as equal, even
when the lazy proc allocation optimization is used.

Implements [Feature #14267]
This commit is contained in:
Jeremy Evans 2020-06-01 12:28:05 -07:00
parent b3aff6a11c
commit 878af5147d
Notes: git 2020-06-20 04:58:52 +09:00
5 changed files with 93 additions and 9 deletions

View file

@ -36,26 +36,26 @@ describe :proc_equal, shared: true do
a.send(@method, b).should be_false
end
it "returns true if both procs have the same body and environment" do
it "returns false if procs are distinct but have the same body and environment" do
p = proc { :foo }
p2 = proc { :foo }
p.send(@method, p2).should be_true
p.send(@method, p2).should be_false
end
it "returns true if both lambdas with the same body and environment" do
it "returns false if lambdas are distinct but have same body and environment" do
x = -> { :foo }
x2 = -> { :foo }
x.send(@method, x2).should be_true
x.send(@method, x2).should be_false
end
it "returns true if both different kinds of procs with the same body and env" do
it "returns false if using comparing lambda to proc, even with the same body and env" do
p = -> { :foo }
p2 = proc { :foo }
p.send(@method, p2).should be_true
p.send(@method, p2).should be_false
x = proc { :bar }
x2 = -> { :bar }
x.send(@method, x2).should be_true
x.send(@method, x2).should be_false
end
it "returns false if other is not a Proc" do