In Ubuntu, The default umask on Ubuntu is
touch test.rb # Its content is: puts "hello world"
ls -l demo.rb # -rw-r--r--
ruby test.rb # output: "hello world"
You are not executing the file as a binary. You are executing
ruby binary with argument
test.rb and it interprets the Ruby script. Therefore, only
ruby binary needs execution privilage and not the script itself.
You can check the privileges of the binary by running
stat (which ruby).
On the other hand if you place
on the top of your script and make it executable with
chmod a+x test.rb you could then make Linux run it. The
binfmt module of the kernel will check search for
#! (called shebang) in the file and run the interpreter for you.
You can find this shebang in lot of the shell scripts. Nowadays it is common to put
#!/usr/bin/env ruby or
#!/usr/bin/env python in order to use interpreter binary in other location that is available on
PATH variable like
env is just another binary program. It will run its argument as a program. The kernel will pass script as the parameter which will result in command
/usr/bin/env ruby test.rb.