Subtraction doesn’t work. And I’ve tried &, | and ^. Do I have to
do some sort compliments operation here? What’s the trick to this?
FYI, on the command line it’s as easy as:
$ chmod a-w file
More specifically, then, you want to remove the write permission from
the file, leaving it whatever other permissions were already set
(possibly none!). In other words, you want to /mask out/ the write bits
from whatever the current file mode is. Try the following:
As far as I can tell, these approaches are functionally equivalent in
both result and efficiency. Folding the method I used all together
using your settings for mode and mask makes mine as follows:
new_mode = mode & (mode ^ mask)
I suspect that someone who more recently completed their college
philosophy of logic class than I might even remember how to derive one
of our solutions from the other using tidy boolean algebra. I’m too
rusty for it at the moment unfortunately, but I did give it a try.
On 02/06/2012 01:38 PM, Intransition wrote:
More specifically, then, you want to remove the write permission from
the file, leaving it whatever other permissions were already set
(possibly none!). In other words, you want to /mask out/ the write bits
from whatever the current file mode is. Try the following:
As far as I can tell, these approaches are functionally equivalent in
both result and efficiency.
Yeah, for all practical purposes I believe this is absolutely correct.
In a compiled language like C there might be a difference though
since my version uses two times the same constant and only one input
variable while your folded version below uses the input twice. But
that is certainly microoptimization one should only do when
implementing a gigabit router or something with similar need for
speed.
Maybe I’ll pick at it more tomorrow…
Kind regards
robert
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.