Class: Object

Inherits:
BasicObject
Defined in:
lib/what_the/constant_helper.rb,
lib/what_the/given_when_then_helper.rb

Overview

Class Method Summary collapse

Class Method Details

.with_constants(constants, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/what_the/constant_helper.rb', line 3

def self.with_constants(constants, &block)
  saved_constants = {}
  constants.each do |constant, val|
    saved_constants[ constant ] = const_get( constant )
    Kernel::silence_warnings { const_set( constant, val ) }
  end

  begin
    block.call
  ensure
    constants.each do |constant, val|
      Kernel::silence_warnings { const_set( constant, saved_constants[ constant ] ) }
    end
  end
end