Pathname.ensure_writable

Yields after chmoding (if necessary), once block is complete restores permissions.
This commit is contained in:
Max Howell 2010-05-10 01:10:49 +01:00 committed by Adam Vandenberg
parent 55bd25ff4c
commit 123f7cd00e

View File

@ -238,6 +238,16 @@ class Pathname
def / that
join that.to_s
end
def ensure_writable
saved_perms = unless writable?
chmod 0644
stat.mode
end
yield
ensure
chmod saved_perms if saved_perms
end
end
# sets $n and $d so you can observe creation of stuff