Method: Cond::Wrapping#wrap_instance_method
- Defined in:
- lib/cond/wrapping.rb
#wrap_instance_method(mod, method) ⇒ Object
Allow handlers to be called from C code by wrapping a method with begin/rescue. Returns the aliased name of the original method.
See the README.
Example:
Cond.wrap_instance_method(Fixnum, :/)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cond/wrapping.rb', line 14 def wrap_instance_method(mod, method) original = "cond_original_#{mod.inspect}_#{method.inspect}" # TODO: jettison 1.8.6, remove eval and use |&block| mod.module_eval " alias_method :'\#{original}', :'\#{method}'\n def \#{method}(*args, &block)\n begin\n send(:'\#{original}', *args, &block)\n rescue Exception => e\n raise e\n end\n end\n eval_end\n original\nend\n" |