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 <<-CODE def #{method}!(*args, &block) result = #{method}(*args, &block) raise #{exception_class} unless result result end CODE end end |