From: David Pollak Date: 2006-04-26T08:02:14+09:00 Subject: Re: Safe Mode Lowering ------=_Part_24671_16513473.1146006123105 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Jake, Here's code that will do what you want: module SafeDo require 'monitor' def safe_do(safe_level) ret =3D nil waiter =3D '' waiter.extend(MonitorMixin) wait_cond =3D waiter.new_cond is_exception =3D false is_done =3D false Thread.start do begin $SAFE =3D safe_level ret =3D yield is_done =3D true waiter.synchronize do wait_cond.signal end rescue Exception =3D> e ret =3D e is_exception =3D true is_done =3D true waiter.synchronize do wait_cond.signal end end end waiter.synchronize do wait_cond.wait_while { !is_done } end raise ret if is_exception return ret end end Thanks, David On 4/25/06, Jake McArthur wrote: > > I am aware that the safe mode in Ruby can only be set higher, not > lower. This makes sense, as unsafe code should not be able to lower > the safe mode. However, is there a way to lower it at all, as I can > think of many times this may be useful. Would it not make a lot more > sense to be able to do something like this? > > safe_mode(x) do # x must be greater than the current safe mode > # do risky code here > end > # back to original safe mode > > Maybe the above is possible and I am just missing how, but I would > think that it would be much more useful to have in a form similar to > this all the time. > > - Jake McArthur > > -- -------- David Pollak's Ruby Playground http://dppruby.com ------=_Part_24671_16513473.1146006123105--