1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
require "forwardable"
require "thread"
module Hamster
# @private
module ReadCopyUpdate
extend Forwardable
def initialize(content)
@content = content
@lock = Mutex.new
end
def eql?(other)
instance_of?(other.class) && @content.eql?(other.instance_variable_get(:@content))
end
alias :== :eql?
def_delegator :@content, :inspect
def_delegator :@content, :to_s
protected
def transform
@lock.synchronize do
@content = yield(@content)
end
self
end
private
def method_missing(name, *args, &block)
@content.send(name, *args, &block) rescue super
end
end
end
|