Top Level Namespace
Defined Under Namespace
Modules: Formatter, GlobalHelpers Classes: HTML, Livetext, Object, Processor, StringParser
Instance Method Summary collapse
Instance Method Details
#make_exception(sym, str, target_class = Object) ⇒ Object
More later?
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/livetext/errors.rb', line 4 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.dup) 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 |