# File lib/eventmachine.rb, line 1301
1301:   def self.watch_file(filename, handler=nil, *args)
1302:     klass = if (handler and handler.is_a?(Class))
1303:       raise ArgumentError, 'must provide module or subclass of EventMachine::FileWatch' unless FileWatch > handler
1304:       handler
1305:     else
1306:       Class.new( FileWatch ) {handler and include handler}
1307:     end
1308: 
1309:     arity = klass.instance_method(:initialize).arity
1310:     expected = arity >= 0 ? arity : -(arity + 1)
1311:     if (arity >= 0 and args.size != expected) or (arity < 0 and args.size < expected)
1312:       raise ArgumentError, "wrong number of arguments for #{klass}#initialize (#{args.size} for #{expected})"
1313:     end
1314: 
1315:     s = EM::watch_filename(filename)
1316:     c = klass.new s, *args
1317:     # we have to set the path like this because of how Connection.new works
1318:     c.instance_variable_set("@path", filename)
1319:     @conns[s] = c
1320:     block_given? and yield c
1321:     c
1322:   end