Sha256: 82e4d75185c633bb1a58dc88578fb912b118d16174f71a9a18ff09706d2f62dd

Contents?: true

Size: 653 Bytes

Versions: 1

Compression:

Stored size: 653 Bytes

Contents

require 'thread_parent/version'
require 'thread'

module ThreadParent

  class Parents

    def initialize(child)
      @child = child
    end

    def [](key)
      if @child.key?(key)
        @child[key]
      else
        @child.parent.parents[key]
      end
    end
  end
end

class Thread

  alias_method :_initialize, :initialize

  def initialize(*args, &block)
    @_parent = Thread.current
    _initialize(*args, &block)
  end

  def parent
    @_parent
  end

  def parents
    ThreadParent::Parents.new(self)
  end

  def self.parent
    Thread.current.parent
  end

  def self.parents
    ThreadParent::Parents.new(Thread.current)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
thread-parent-1.0.2 lib/thread_parent.rb