Sha256: 1500a55189c87519404749ab059521e8a74de93f801fdaff65cb70187a78c50b

Contents?: true

Size: 617 Bytes

Versions: 1

Compression:

Stored size: 617 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]
      elsif @child.parent
        @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.parents
    ThreadParent::Parents.new(Thread.current)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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