Within how many lines from the beginning do various directions have to be placed?

Viewed 183

There are various directions following a comment character # that are interpreted in a specific way.

  • UNIX shebang: #!/usr/bin/env ruby
  • magic comment for encoding (used in Ruby 1.9): #coding: UTF-8
  • frozen string literal pragma: #frozen_string_literal: true
  • ruby-mode direction for text editors (like emacs): #!ruby
  • vim encoding direction: #vim:set fileencoding=euc-jp

It is clear that they have to be placed near the beginning of the file to work correctly, but when there are more than one of them, they cannot all be placed on the first line. Within how many lines from the beginning of the file do they have to be placed? Is the relative order between them relevant? What are the rules that decide them?

If there are other than those I listed above, please add that.

1 Answers
Related