From: Gavin Sinclair Date: 2005-10-23T14:27:00+09:00 Subject: Re: Find the test dir Trans wrote: > Don't know how much gulf this can take, but I sure would like as small > a version as I can get. > > paths = File.expand_path(File.dirname(__FILE__)).split('/') > paths.size.downto(1) do |i| > f = (paths.slice(0..i)+['test']).join('/') > $TESTDIR = File.join(f,'FIXTURE') if File.directory?(f) > end > raise unless $TESTDIR The best balance between size and readability is probably the following: find_test_dir Of course, the method "find_test_dir" must be implemented somewhere, but you won't have to read it very often, and you can just use the six lines you've written above. However, I would use the 'pathname' library to clarify some of the code. Cheers, Gavin