Define a thread local variable for the current instance with name name. If the value value is given, it is used to initialize the variable.
# File lib/dslkit/polite.rb, line 93 def instance_thread_local(name, value = nil) sc = class << self extend DSLKit::ThreadLocal self end sc.thread_local name, value self end
Define a thread local variable named name in this module/class. If the value value is given, it is used to initialize the variable.
# File lib/dslkit/polite.rb, line 66 def thread_local(name, value = nil) is_a?(Module) or raise TypeError, "receiver has to be a Module" name = name.to_s my_id = "__thread_local_#{__id__}__" ObjectSpace.define_finalizer(self, @@cleanup) define_method(name) do Thread.current[my_id] ||= {} Thread.current[my_id][name] end define_method("#{name}=") do |value| Thread.current[my_id] ||= {} Thread.current[my_id][name] = value end if value Thread.current[my_id] = {} Thread.current[my_id][name] = value end self end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.