Method: Thread#thread_variable?
- Defined in:
- thread.c
#thread_variable?(key) ⇒ Boolean
Returns true if the given string (or symbol) exists as a thread-local variable.
me = Thread.current
me.thread_variable_set(:oliver, "a")
me.thread_variable?(:oliver) #=> true
me.thread_variable?(:stanley) #=> false
Note that these are not fiber local variables. Please see Thread#[] and Thread#thread_variable_get for more details.
3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 |
# File 'thread.c', line 3935
static VALUE
rb_thread_variable_p(VALUE thread, VALUE key)
{
VALUE locals;
VALUE symbol = rb_to_symbol(key);
if (LIKELY(!THREAD_LOCAL_STORAGE_INITIALISED_P(thread))) {
return Qfalse;
}
locals = rb_thread_local_storage(thread);
return RBOOL(rb_hash_lookup(locals, symbol) != Qnil);
}
|