# $SAFE reset when proc called (1.8.4)

**URL:** <https://www.ruby-forum.com/t/safe-reset-when-proc-called-1-8-4/87790>\
**Category:** Ruby\
**Created:** [March 6, 2007, 12:38am UTC](https://www.ruby-forum.com/t/safe-reset-when-proc-called-1-8-4/87790 "2007-03-06T00:38:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kelleysislander](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f6c823/32.png) [@kelleysislander](https://www.ruby-forum.com/u/kelleysislander)\
**Post date:** [March 6, 2007, 12:38am UTC](https://www.ruby-forum.com/t/safe-reset-when-proc-called-1-8-4/87790/1 "2007-03-06T00:38:17Z")

</div>

Hi,

I’m wondering if this is a bug? When the proc is called, the  
safe\_level is reverting to zero:

$ cat safe-test4.rb

pr = lambda{ puts “my\_safe\_level=#{Thread.current.safe\_level}” }

th = Thread.new(pr) do |pr\_|  
$SAFE = 4  
pr\_.call  
end  
th.join

$ ruby -v safe-test.rb  
ruby 1.8.4 (2005-12-24) [i386-mswin32]  
my\_safe\_level=0

If this isn’t a bug, does anyone know why this behavior would  
be desirable?

Thanks,

Regards,

Bill

---

<div class="post-metadata">

**Author:** ![kelleysislander](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f6c823/32.png) [@kelleysislander](https://www.ruby-forum.com/u/kelleysislander)\
**Post date:** [March 6, 2007, 12:42am UTC](https://www.ruby-forum.com/t/safe-reset-when-proc-called-1-8-4/87790/2 "2007-03-06T00:42:17Z")

</div>

> my\_safe\_level=0
> 
> If this isn’t a bug, does anyone know why this behavior would  
> be desirable?

AFAIK, that’s the desired behavior - the pr proc was created while  
$SAFE=0 and will be executed in that $SAFE=0 context. That allows you to  
give a Safe environment access to unsafe things.

Dan.

---

<div class="post-metadata">

**Author:** ![kelleysislander](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f6c823/32.png) [@kelleysislander](https://www.ruby-forum.com/u/kelleysislander)\
**Post date:** [March 6, 2007, 1:10am UTC](https://www.ruby-forum.com/t/safe-reset-when-proc-called-1-8-4/87790/3 "2007-03-06T01:10:19Z")

</div>

From: “Daniel S.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> AFAIK, that’s the desired behavior - the pr proc was created while  
> $SAFE=0 and will be executed in that $SAFE=0 context. That allows you to  
> give a Safe environment access to unsafe things.

Oh. I guess that is pretty cool. 🙂

Just inconvenient in my particular situation, but I can work  
around it.

Thanks,

Bill
