module Nuggets::Env::SetMixin
Public Instance Methods
set([env[, clear]]) → aHash
click to toggle source
set([env[, clear]]) { ... } → anObject
Overrides ENV with env
, clearing it beforehand if clear
is true
. If a block is given, restores ENV to its original state afterwards and returns the result of the block; otherwise returns the original ENV as a hash.
# File lib/nuggets/env/set_mixin.rb 38 def set(env = {}, clear = true) 39 old_env = to_hash 40 41 self.clear if clear 42 43 env.each { |key, value| 44 key = key.to_s.upcase unless key.is_a?(::String) 45 value = value.to_s unless value.is_a?(::String) 46 47 self[key] = value 48 } 49 50 block_given? ? yield : old_env 51 ensure 52 set(old_env) if old_env && block_given? 53 end
Also aliased as: without
with([env[, clear]]) { ... } → anObject
click to toggle source
Temporarily overrides ENV with env
for the block execution. See set
.
# File lib/nuggets/env/set_mixin.rb 61 def with(env = {}, clear = false) 62 set(env, clear) { yield } 63 end