Module: Scriptorium::Exceptions
- Defined in:
- lib/skeleton.rb,
lib/scriptorium/exceptions.rb
Instance Method Summary collapse
Instance Method Details
#make_exception(sym, str, target_class = Object) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/scriptorium/exceptions.rb', line 3 def make_exception(sym, str, target_class = Object) return if target_class.constants.include?(sym) klass = sym # :"#{sym}_Class" target_class.const_set(klass, StandardError) define_method(sym) do |*args| args = [] unless args.first msg = str.dup args.each.with_index {|arg, i| msg.sub!("%#{i+1}", arg.to_s) } target_class.class_eval(klass.to_s).new(msg) end end |