From 075a102c937969c62a6798b32b3c3188df91a075 Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Tue, 5 Nov 2024 04:43:24 +0900 Subject: [PATCH] `Ractor.[]` and `Ractor.[]=` `Ractor#[]/[]=` is only for accessors to the current ractor, so that `Ractor.[]/[]=` is simpler. [Feature #20715] --- ractor.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ractor.rb b/ractor.rb index 6a83d3a92f..d6eeb987b2 100644 --- a/ractor.rb +++ b/ractor.rb @@ -834,16 +834,26 @@ class Ractor end end - # get a value from ractor-local storage + # get a value from ractor-local storage of current Ractor def [](sym) Primitive.ractor_local_value(sym) end - # set a value in ractor-local storage + # set a value in ractor-local storage of current Ractor def []=(sym, val) Primitive.ractor_local_value_set(sym, val) end + # get a value from ractor-local storage of current Ractor + def self.[](sym) + Primitive.ractor_local_value(sym) + end + + # set a value in ractor-local storage of current Ractor + def self.[]=(sym, val) + Primitive.ractor_local_value_set(sym, val) + end + # returns main ractor def self.main __builtin_cexpr! %q{