See this Pastie, which makes use of
detect and an ERb variable.
On the #rubyonrails.se IRC channel, simmel made the recipe better by adding the check for
File.socket?, instead of
File.socket? will follow symbolic links, as you can see in the pasted code.)
A recipe variation, you might call it.