Here is my method. It checks if the file is usable. How do I dry this out?
@@filepath = nil
def self.file_usable?
return false unless @@filepath
return false unless File.exists?(@@filepath)
return false unless File.readable?(@@filepath)
return false unless File.writable?(@@filepath)
return true
end
Should I be using some kind of loop?
I wouldn’t do it this way, but since you asked “to just refactor all these methods action on the same variable”…
This may be useful if you programatically need to decide which methods must be checked. If that’s an isolated function, I’d write: