From: "zverok (Victor Shepelev) via ruby-core" <ruby-core@...> Date: 2023-02-25T17:54:53+00:00 Subject: [ruby-core:112608] [Ruby master Feature#19377] Rename Fiber#storage to Fiber.storage Issue #19377 has been updated by zverok (Victor Shepelev). @Eregon My argument was not about `#storage` taken alone, but about `#storage` vs `::[]` inconsistency. The inconsistency can be fixed either way (e.g. if "it may evolve", then why don't we do `Fiber.current['name']` from the very beginning?) > Additionally, Fiber#storage and Fiber#storage= are expected to be much rarer to use. Right, but methods like this are frequently used when learning the language and investigating/debugging "how things are", so again, inconsistency strikes here. > IMHO it would feel weird to have them as class methods on `Fiber`. Does `Fiber[foo]` not feel weird? (For me it actually does, seems like something "global", not local to the current fiber at all) ---------------------------------------- Feature #19377: Rename Fiber#storage to Fiber.storage https://bugs.ruby-lang.org/issues/19377#change-102055 * Author: zverok (Victor Shepelev) * Status: Open * Priority: Normal ---------------------------------------- Justification: * `#storage`, which pretends to be an instance method, is always available only on `Fiber.current`, which is [problematic to document](https://github.com/ruby/ruby/pull/6985#discussion_r1055796069), and needs special handling when `storage` is called for non-current Fiber; * with class method + docs "storage of the current fiber" it all will be self-evident; * Most of the time, when we declare methods that are available only in the current {something}, they are class methods. (like storage's itself interface of `Fiber::[]` and `Fiber::[]=`, or `Module.used_modules`, which is modules and refinements of the _current context_, but it is not `self.used_modules`, for example) * Code like ```ruby Fiber.current.storage = {foo: 'bar'} Fiber[:foo] ``` ...looks like it is two unrelated things (storage of the _current_ fiber vs some "global" key getter/setter?) I don't see much discussion of this in #19078. Matz in #19078#note-22, while accepting the interface, describes it as homogenous: > (1) fiber[key]/fiber[key]=val - accepted. > (2) fiber.storage => hash - accepted > (3) fiber.storage=hash - should be experimental > ... So I believe it should be either `Fiber.current[]` and `Fiber.current.storage`, or `Fiber[]`, and `Fiber.storage`. The latter is preferable to underline it is only one, related to the current fiber, interface, not "every fiber instance has one (but actually you can use only `current`'s) -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/