From: "Jonas Pfenniger (zimbatm)" Date: 2011-01-09T09:05:05+09:00 Subject: Re: Best way for Array#find+transform ? 2011/1/8 Anurag Priyam : >> paths.map{|path| File.join(path, filename)}.select{|name| File.exist?(path)} > > Of course, I meant to use name, instead of path in the last section. So: > > file = paths.map{|path| File.join(path, filename)}.select{|name| > File.exist?(name)} Yes, if you replace #select by #find, then it is correct, you'll get the same result as my algorithm. But if the result is in the first entry, then all subsequent paths are unnecessarily joined. Another version of the algorithm would be: path = paths.find{|p| File.exist?(File.join(p, filename)) } if path abs_path = File.join(path, filename) end In this version, not all the paths are joined, but File.join is called two times on the resulting path if any. In any case, it is not a life-or-death issue, but any ways I look at it, there is still that small imperfection that annoys me :)