Search code examples
rubysinatra

By mistake, I called a Sinatra Ruby file app.py and it still worked, why?


I named a Ruby file app.py and it worked. I only noticed later. Why is that possible. It wasn't anything complicated, just a small Sinatra recipe but still, I don't understand.


Solution

  • Under Unix (say, Linux or similar), the first line of a script contains the path to its interpreter. The line's called Shebang or Crunchbang and looks like that:

    #! /usr/bin/ruby

    If you rename you file, the path to the interpreter still remains unchanged and therefore the script will be executed as before.