title: Setting file permissions in Ruby with File.open
body: <p>I wrote this to survey the permissions of files created with varying <code>perm</code> values</p>
  
  <pre><code>[0644, 0664, 0755, 0775].each do |perm|
    filename = "file#{perm}"
    File.open(filename, 'wb', perm) { |f| f.puts 'test' }
    puts '%o' % File::Stat.new(filename).mode
  end
  </code></pre>
  
  <p>When run this will output:</p>
  
  <pre><code>100644
  100644
  100755
  100755
  </code></pre>
  
  <p>Which is not what I expected. Why is the group write permission on the 2nd and 4th file not set?</p>