On Unix/Linux systems, the chmod function supports “symbolic modes”, meaning you can do what is essentially bit-arithmetic with permissions, e.g. chmod u+x ... is a symbolic form for adding executable permissions for the user. The chmod function in Ruby’s FileUtils only supports an absolute bitmask as a permission, i.e. you can only do FileUtils.chmod(0777, ...) but FileUtils.chmod('u+x', ...) will not work.
I get that one way to do this is to just call the system command directly: system("chmod u+x ..."), but I’d prefer to keep code in the Ruby domain as much as possible without spawning shells everywhere. Alternatively, I could iterate through File objects, File.stat them, get their existing bitmasks and modify them individually, but symbolic modes will support a file glob, which is much more succinct and less error prone.
Does anyone know whether there is a way to do this in a more elegant way?
What version of Ruby are you using? Look at the 1.9.3 docs for FileUtils.chmod: