blob: 1a10b90689f7a83b703eb6366800bc535cae6195 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
|