Joel VanderWerf
7/27/2008 7:19:00 PM
Kip Cole wrote:
> So the question is: what is the right way to achieve the desired result.
> Where the desired result is to pass a block to a method to be executed
> in a different context, without the caller having to know any of the
> implementation details.
What about this?
Context = Struct.new :user
def sudo
context = Context.new
context.user = "admin_user"
yield context
end
outer_context = Context.new
outer_context.user = "normal_user"
puts "I am #{outer_context.user}"
sudo do |context|
puts "I am #{context.user}"
end
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407