Sha256: da69d8356e0834404bbeebab50b883549ebd2f402d112836652b9e71375556c3

Contents?: true

Size: 406 Bytes

Versions: 7

Compression:

Stored size: 406 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) }
    target_class.class_eval(klass.to_s).new(msg)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
livetext-0.9.22 lib/errors.rb
livetext-0.9.21 lib/errors.rb
livetext-0.9.20 lib/errors.rb
livetext-0.9.19 lib/errors.rb
livetext-0.9.17 lib/errors.rb
livetext-0.9.15 lib/errors.rb
livetext-0.9.14 lib/errors.rb