1220: def self.open_keyboard handler=nil, *args
1221: klass = if (handler and handler.is_a?(Class))
1222: raise ArgumentError, 'must provide module or subclass of EventMachine::Connection' unless Connection > handler
1223: handler
1224: else
1225: Class.new( Connection ) {handler and include handler}
1226: end
1227:
1228: arity = klass.instance_method(:initialize).arity
1229: expected = arity >= 0 ? arity : -(arity + 1)
1230: if (arity >= 0 and args.size != expected) or (arity < 0 and args.size < expected)
1231: raise ArgumentError, "wrong number of arguments for #{klass}#initialize (#{args.size} for #{expected})"
1232: end
1233:
1234: s = read_keyboard
1235: c = klass.new s, *args
1236: @conns[s] = c
1237: block_given? and yield c
1238: c
1239: end