"Lloyd Zusman" <ljz / asfast.com> schrieb im Newsbeitrag news:m33c383xee.fsf / asfast.com... > > Here's another idea: put your code into two files and require (or load) the > > helper code. > > I know that I can do that. But often I just want one file. I believe > that the best use of `require' or `load' is to include code from shared > libraries. Putting simple subsidiary routines in one or more separate > files often complicates installation and maintenance. True. It's a tradeoff: it seemed to me that having prototypes was a paramount requirement of you. > > Or put your helper code after __END__ and use eval to compile it: > > > > [ ... etc. ... ] > > That can work, but if I ever want to put real data after __END__ and > read it via the DATA handle, I'd be out of luck. Yes, of course. > >> Never fear ... the code that I write tends to look ruby-ish and not > >> C-like. :) > > > > Dare you! :-) > > OK. Attached is a ruby program that I recently wrote. It is a > specialized "tail -f". In addition to standard "tail -f" capabilities, > it also can simultaneously tail multiple files, and in addition, it will > detect if a new file has replaced the one that is being tailed, in which > case it starts tailing the newly created file automatically. <snip/> > Here's the code ... Very nice! I like especially the documentation. Some remarks from cursory glancing though: - I would not use Thread.critical since it is error prone. *If* you use it, you should use this idiom, because it ensures that Thread.critical is reset properly: Thread.critical = true begin # stuff ensure Thread.critical = false end But, in your example this is superior: require 'monitor' # My list of threads. $fileThreads = [].extend MonitorMixin # later $fileThreads.synchronize do # do stuff with $fileThreads end - You are using exit a bit too much IMHO, especially since you have "exit(rtail)" but rtail invokes exit, too. Usage of exit reduces reusability of code and thus I would limit it to the to level of the script, something like begin # do MAIN stuff exit 0 rescue Exception => e $stderr.puts e exit 1 end And within the rest of the script I'd use exceptions. Patterns like this are inferior begin block = self.read(testsize) rescue return false end # further code that works with block Instead put all the code for the clean case into the block or leave the rescue completely out here and handle the exception on a higher level. That makes things much easier. - There is File.split: # old: $program = $0.sub(/^.*\//, '') $dir, $program = File.split $0 I hope, that was not too frustrating... :-) Regards robert