From: Julian Leviston Date: 2009-02-04T11:05:45+09:00 Subject: Re: File.delete one-liner File.delete(File.exists?(lockfile) ? lockfile : @lockfile) Blog: http://random8.zenunit.com/ Learn rails: http://sensei.zenunit.com/ On 04/02/2009, at 5:07 AM, Joel VanderWerf wrote: > 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 >