Sha256: 1d039b915de8058b41fb9e4149a2b1b22f26df0401a88011836964651399a6fa
Contents?: true
Size: 558 Bytes
Versions: 14
Compression:
Stored size: 558 Bytes
Contents
# More later? 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 make_exception(:EndWithoutOpening, "Error: found .end with no opening command") make_exception(:UnknownMethod, "Error: name '%1' is unknown")
Version data entries
14 entries across 14 versions & 1 rubygems