Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Thread#thread_variable_set
(untyped key, untyped value) -> untyped
thr.thread_variable_set(key, value)
thread.c
View on GitHub ↗
static VALUE
rb_thread_variable_set(VALUE thread, VALUE key, VALUE val)
{
VALUE locals;
if (OBJ_FROZEN(thread)) {
rb_frozen_error_raise(thread, "can't modify frozen thread locals");
}
locals = rb_thread_local_storage(thread);
return rb_hash_aset(locals, rb_to_symbol(key), val);
}
Sets a thread local with key to value. Note that these are local to threads, and not to fibers. Please see Thread#thread_variable_get and Thread#[] for more information.
See also
#thread_variables
#to_s
#thread_variable_get
#value
also in
4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0