Sha256: 9309e6a3a572fe9b2238b2a4f0b844c755537292cf386c892dc92023874eba00
Contents?: true
Size: 519 Bytes
Versions: 10
Compression:
Stored size: 519 Bytes
Contents
module Kernel # Temporarily set variables while yielding a block, then return the # variables to their original settings when complete. # # temporarily('$VERBOSE'=>false) do # $VERBOSE.assert == false # end # def temporarily(settings) #:yield: cache = {} settings.each do |var, val| cache[var] = eval("#{var}") eval("proc{ |v| #{var} = v }").call(val) end yield ensure cache.each do |var, val| eval("proc{ |v| #{var} = v }").call(val) end end end
Version data entries
10 entries across 9 versions & 2 rubygems