Forum: Ruby When is $SAFE reset?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bertram S. (Guest)
on 2006-01-19 03:34
(Received via mailing list)
Hi,

irb(main):001:0> begin ; $SAFE=2 ; end ; puts $SAFE
2
irb(main):002:0> puts $SAFE
0
irb(main):003:0> def s ; $SAFE=2 ; end ; s ; puts $SAFE
2
irb(main):004:0> puts $SAFE
0
irb(main):005:0> eval "$SAFE=2; puts $SAFE" ; puts $SAFE
2
0
rb(main):007:0> eval "$SAFE=1; eval '$SAFE=2; puts $SAFE' ; puts $SAFE"
; puts $SAFE
2
1
0

Obviously, $SAFE will be reset after `eval' expressions have
completed. Are there (besides threads) other cases where
$SAFE is reset? And if not: why will it be reset after
every `eval'?

Thanks in advance,

Bertram
This topic is locked and can not be replied to.