[Bug #20978] Stringize Fiber storage keys

This commit is contained in:
Nobuyoshi Nakada 2024-12-23 18:16:28 +09:00
parent a11bb36316
commit adad97a031
No known key found for this signature in database
GPG key ID: 3582D74E1FEE4465
Notes: git 2024-12-23 11:13:09 +00:00
3 changed files with 25 additions and 2 deletions

View file

@ -90,7 +90,9 @@ ruby_version_is "3.2" do
key = :"#{self.class.name}#.#{self.object_id}"
Fiber.new { Fiber[key] = 42; Fiber[key] }.resume.should == 42
end
end
ruby_version_is "3.2.3"..."3.4" do
it "can't use invalid keys" do
invalid_keys = [Object.new, "Foo", 12]
invalid_keys.each do |key|
@ -99,6 +101,15 @@ ruby_version_is "3.2" do
end
end
ruby_version_is "3.4" do
it "can use keys as strings" do
key = Object.new
def key.to_str; "Foo"; end
Fiber[key] = 42
Fiber["Foo"].should == 42
end
end
it "can access the storage of the parent fiber" do
f = Fiber.new(storage: {life: 42}) do
Fiber.new { Fiber[:life] }.resume