Skip to content

Instantly share code, notes, and snippets.

@sshaw
Last active March 20, 2016 03:03
Show Gist options
  • Save sshaw/1190047 to your computer and use it in GitHub Desktop.
Save sshaw/1190047 to your computer and use it in GitHub Desktop.
Ruby String class extensions for checking file permissions
class String
MODES={"r" => :readable?, "w" => :writable?, "x" => :executable?}
def permission?(file)
self.split(//).inject(true) { |can, m| can && MODES.include?(m) && File.send(MODES[m], file) }
end
end
"rw".permission?("Makefile.PL")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment