Module: ThreadVariable
Constant Summary collapse
- VERSION =
'0.2.0'
Instance Method Summary collapse
Instance Method Details
#thread_variable(*names) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/thread_variable.rb', line 4 def thread_variable *names names.each do |name| namespace = (self.name || self.object_id.to_s).to_sym define_singleton_method :"#{name}" do (Thread.current[namespace] ||= {})[name] end define_singleton_method :"#{name}=" do |val| (Thread.current[namespace] ||= {})[name] = val end end end |