ONCE_CACHE={}ONCE_MUTEX=Mutex.newdefONCE(&b)raiseunlessblock_given?ONCE_MUTEX.synchronize{key=caller(3,1)[0]ifvalue=ONCE_CACHE[key]valueelseONCE_CACHE[key]=yieldend}end3.times{|i|pONCE{i#=> every time 0}}

##

Note that this code doesn't work if two or more ONCE{} are available in one line.¶