Method: #with

Defined in:
lib/context_manager.rb

#with(*args) ⇒ Object

Raises:



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/context_manager.rb', line 7

def with(*args)
  begin
    arg = args[0]
    yield_obj = arg[0]
  rescue
    raise ContextNotFound, 'no context found'
  end

  raise ContextNotFound, 'no context found' if yield_obj.nil?

  begin
    yield yield_obj
  ensure
    arg[1].call(yield_obj)
  end
end