module Fiber::Local

Constants

VERSION

Public Instance Methods

instance() click to toggle source

Get the current thread-local instance. Create it if required. @returns [Object] The thread-local instance.

# File lib/fiber/local.rb, line 36
def instance
        thread = Thread.current
        name = self.name
        
        if instance = thread[self.name]
                return instance
        end
        
        unless instance = thread.thread_variable_get(name)
                if instance = self.local
                        thread.thread_variable_set(name, instance)
                end
        end
        
        thread[self.name] = instance
        
        return instance
end
instance=(instance) click to toggle source

Assigns to the fiber-local instance. @parameter instance [Object] The object that will become the thread-local instance.

# File lib/fiber/local.rb, line 57
def instance= instance
        thread = Thread.current
        thread[self.name] = instance
end
local() click to toggle source

Instantiate a new thread-local object. By default, invokes {new} to generate the instance. @returns [Object]

# File lib/fiber/local.rb, line 30
def local
        self.new
end