From: Robert Dober Date: 2008-12-27T19:08:48+09:00 Subject: Re: Are all Ruby built-in objects thread safe? On Sat, Dec 27, 2008 at 10:04 AM, Simon Krahnke wrote: > * Robert Klemme (11:23) schrieb: > >> if hash.contains_key? k >> dat = hash[k] >> else >> dat = create_dat(k) >> hash[k] = dat >> end > >> [...] > >> So in this case you need a lock around the _complete_ block of code. >> (Note, the method level lock would work if using a Hash with a default >> block, but this solves only a small portion of the cases.) > > If Hash had a method get_with_default that took a default value or a I believe you mean "get and assign with default" because IIRC there is a get_with_default, it is simply called Hash#fetch R.