Skip to content

Instantly share code, notes, and snippets.

@qerub qerub/gist:4fe10adbafebfa29c7b7 Secret
Created Apr 22, 2013

Embed
What would you like to do?
require "thread"
class Ref
def initialize(data = Hamster.hash)
@mutex = Mutex.new
@data = data
end
def update
@mutex.synchronize do
begin
@data = yield @data
rescue => ex
puts "Error occurred in Ref#update: #{ex.message}"
@data
end
end
end
def current
@data
end
end
ref = Ref.new
ref.update do |hash|
hash.put(:temperature, 27).put(:unit, "F")
end
data = ref.current
puts "The current temperature is: #{data[:temperature]} #{data[:unit]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.