Top Level Namespace
Defined Under Namespace
Classes: ContextNotFound
Instance Method Summary collapse
Instance Method Details
#cm_fopen(filename) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/context_manager.rb', line 24 def cm_fopen(filename) f = File.open(filename) close_file = finish do |file| file.close end [f, close_file] end |
#finish(&block) ⇒ Object
3 4 5 |
# File 'lib/context_manager.rb', line 3 def finish(&block) Proc.new { |obj| block.call(obj) } end |
#with(*args) ⇒ Object
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 |