1202: def EventMachine::open_keyboard handler=nil, *args
1203: klass = if (handler and handler.is_a?(Class))
1204: raise ArgumentError, 'must provide module or subclass of EventMachine::Connection' unless Connection > handler
1205: handler
1206: else
1207: Class.new( Connection ) {handler and include handler}
1208: end
1209:
1210: arity = klass.instance_method(:initialize).arity
1211: expected = arity >= 0 ? arity : -(arity + 1)
1212: if (arity >= 0 and args.size != expected) or (arity < 0 and args.size < expected)
1213: raise ArgumentError, "wrong number of arguments for #{klass}#initialize (#{args.size} for #{expected})"
1214: end
1215:
1216: s = read_keyboard
1217: c = klass.new s, *args
1218: @conns[s] = c
1219: block_given? and yield c
1220: c
1221: end