From: Joel VanderWerf Date: 2009-02-04T03:07:30+09:00 Subject: Re: File.delete one-liner David Stanford wrote: > Hi guys, > > I'm looking for a single line that essentially deletes the lockfile > argument passed to the unlock method, or deletes the instance variable > (default) lockfile. Like this, but simpler: > > @lockfile = some_other_lockfile > > def self.unlock(lockfile) > if File.exist?(lockfile) > File.delete(lockfile) > else > File.delete(@lockfile) > end > end > > > I was thinking of something along the following: > > @lockfile = some_other_lockfile > > def self.unlock > File.delete(lockfile) || File.delete(@lockfile) > end > > ...however, the File.delete method doesn't return a true/false value > based on its success. > > Any tips? Thanks in advance! > > -David Use exceptions? begin File.delete(lf) rescue Errno::ENOENT File.delete(@lf) end -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407