Project

General

Profile

Actions

Bug #20978

closed

Ractor[]/Thread[]/Fiber[] behavior difference

Added by zverok (Victor Shepelev) 18 days ago. Updated 2 days ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.4.0dev (2024-12-22T06:08:19Z master 3808d29e20) +PRISM [x86_64-linux]
[ruby-core:120367]

Description

Ractor.[] and .[]= support string and symbol keys (treating them by string value, and also accepting anything responding to #to_str):

Ractor[:value] = 10
Ractor[:value] #=> 10
Ractor['value'] #=> 10
o = Object.new
def o.to_str = 'value'
Ractor[o] #=> 10

Ractor[1]
# in 'Ractor.[]': 1 is not a symbol nor a string (TypeError)

But Fiber.[] only accept symbols:

Fiber[:value] = 10
Fiber['value']
# in 'Fiber.[]': wrong argument type String (expected Symbol) (TypeError)

Thread#[] and #[]= behave like Ractor’s.

(The documentation for Fiber and Thread follows the reality—while Ractor’s current docs don’t specify key type at all—but the discrepancy feels somewhat weird.)

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0