Class: Thread

Inherits:
Object
  • Object
show all
Defined in:
lib/thread/inheritable_attributes.rb,
lib/thread/inheritable_attributes/version.rb

Defined Under Namespace

Modules: InheritableAttributes

Constant Summary collapse

INHERITABLE_ATTRIBUTES_MUTEX =
Mutex.new

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ Thread

Returns a new instance of Thread.



8
9
10
11
12
13
14
# File 'lib/thread/inheritable_attributes.rb', line 8

def initialize(*args, &block)
  _inheritable_attributes = inheritable_attributes.dup
  _initialize(*args) do |*block_args|
    store[:inheritable_attributes] = _inheritable_attributes
    block.call(block_args)
  end
end

Instance Method Details

#_initializeObject



6
# File 'lib/thread/inheritable_attributes.rb', line 6

alias_method :_initialize, :initialize

#get_inheritable_attribute(key) ⇒ Object



16
17
18
19
20
# File 'lib/thread/inheritable_attributes.rb', line 16

def get_inheritable_attribute(key)
  INHERITABLE_ATTRIBUTES_MUTEX.synchronize do
    inheritable_attributes[key]
  end
end

#set_inheritable_attribute(key, value) ⇒ Object



22
23
24
25
26
# File 'lib/thread/inheritable_attributes.rb', line 22

def set_inheritable_attribute(key, value)
  INHERITABLE_ATTRIBUTES_MUTEX.synchronize do
    inheritable_attributes[key] = value
  end
end