Module: SimpleLock::With

Included in:
SimpleLock
Defined in:
lib/initializers/with.rb

Instance Method Summary collapse

Instance Method Details

#with(**attributes) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/initializers/with.rb', line 5

def with(**attributes)
  old_values = {}
  begin
    attributes.each do |key, value|
      old_values[key] = public_send(key)
      public_send("#{key}=", value)
    end
    yield self
  ensure
    old_values.each do |key, old_value|
      public_send("#{key}=", old_value)
    end
  end
end