From: Bill Kelly Date: 2009-11-12T05:47:28+09:00 Subject: Re: Separate code space/sandbox? From: "Patrik Sundberg" > > I'm interested in figuring out a way to get a separate scope. I do not > need any other traditional sandbox features, i.e. any code goes, I > just want code evaluated in the scope to no affect the parent scope > (at all). Example illustrating what I am after: > > a = 10 > SeparatedScope.new do > a = a + 1 > p a > end > p a > > yielding: > 11 > 10 > > I'd like it to have the same initialization/separation also for > instance variables and even global variables if possible. This isn't very pretty, but... class SeparatedScope def initialize(code) eval(code) end end a = 10 SeparatedScope.new %{ a = 11 p a } p a .... Note there's no access to outer scope variables at all in this case, thus the inner "a = 11" instead of "a = a + 1". :( Regards, Bill