Class: Module
- Inherits:
-
Object
- Object
- Module
- Defined in:
- lib/makitzo/monkeys/bangify.rb
Instance Method Summary collapse
Instance Method Details
#bangify(*methods) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/makitzo/monkeys/bangify.rb', line 2 def bangify(*methods) exception_class = 'RuntimeError' exception_class = methods.pop if (methods.last.is_a?(Class) || methods.last =~ /^[A-Z]/) methods.each do |method| class_eval " def \#{method}!(*args, &block)\n result = \#{method}(*args, &block)\n raise \#{exception_class} unless result\n result\n end\n CODE\n end\nend\n" |