14: def initialize(listen_socket, klass = Socket, *args, &block)
15:
16: unless klass.allocate.is_a? IOWatcher
17: raise ArgumentError, "provided class must descend from IOWatcher"
18: end
19:
20:
21: arity = klass.instance_method(:initialize).arity
22: expected = arity >= 0 ? arity : -(arity + 1)
23:
24: if (arity >= 0 and args.size + 1 != expected) or (arity < 0 and args.size + 1 < expected)
25: raise ArgumentError, "wrong number of arguments for #{klass}#initialize (#{args.size+1} for #{expected})"
26: end
27:
28: @klass, @args, @block = klass, args, block
29: super(listen_socket)
30: end