From: Bertram Scharpf Date: 2005-02-02T06:13:56+09:00 Subject: Re: $SAFE doesn't work as specified? Hi Assaph, Am Dienstag, 01. Feb 2005, 06:50:45 +0900 schrieb Assaph Mehr: > > the Chapter "Locking Ruby in the Safe" says this should > > work: > > This is the expected behaviour: inside the thread you create you set > the $SAFE level to 4, meaning that from here on within the thread you > can't access variables from outside the thread scope. What you can do > is either hardcode the file name in the #load or pass an argument to > the thread: > > | Thread.start(File.expand_path(fn)) { |fn| > | $SAFE = 4 > | load fn, true > | }.join > > The expand_path is because you cannot load a relative path when in > $SAFE >= 2. Thank you very much for your detailed answer. I'm afraid to say the program still doesn't work: $ cat safe.rb fn = 'dummy.rb' File.open fn, 'w' do |f| f.puts 'raise "hello"' end Thread.start( File.expand_path( fn)) do |fn| $SAFE = 4 load fn, true end.join $ ruby safe.rb safe.rb:7:in `load': Insecure operation - load (SecurityError) from safe.rb:5:in `join' from safe.rb:5 $ All I wanted to do is run the thread in its own environment. I will use fork. Bertram -- Bertram Scharpf Stuttgart, Deutschland/Germany http://www.bertram-scharpf.de