Class: Defer::Block

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/defer/block.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(base, &block) ⇒ Object



5
6
7
# File 'lib/defer/block.rb', line 5

def self.run(base, &block)
  new(base).run(&block)
end

Instance Method Details

#defer(&block) ⇒ Object



19
20
21
# File 'lib/defer/block.rb', line 19

def defer(&block)
  _stack.unshift(block)
end

#recoverObject



23
24
25
26
# File 'lib/defer/block.rb', line 23

def recover
  @_recovered = true
  @_exception
end

#run(&block) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/defer/block.rb', line 9

def run(&block)
  ret = instance_eval(&block)
rescue Exception => e
  @_exception = e
ensure
  _cleanup
  raise @_exception if @_exception && !@_recovered
  ret
end