Source/script encoding (magic line)

As you probably know, the source/script encoding can be specified by
putting a “magic comment” line as the first or second line of a Ruby

Being a Vim user, I have used a “magic comment” line like this

# NOTE: vim: fileencoding=UTF-8

Thus, the line could be used by Ruby as well as Vim.

I first learned about the “magic comment” line from the book “The Ruby
Programming Language” by David Flanagan and Matz. According to the book,
the syntax rules for the line are:

The comment must be written entirely in ASCII, and must include the
string “coding” followed by a colon or equals sign and the name of the
desired encoding (which cannot include spaces or punctuation other than
hyphen and underscore). Whitespace is allowed on either side of the
colon or equals sign, and the string “coding” may have any prefix, such
as “en” to spell “encoding”.

However, the documentation
does not entirely agree:

The default script encoding is Encoding::US-ASCII, but it can be changed
by a magic comment on the first line of the source code file (or second
line, if there is a shebang line on the first). The comment must contain
the word “coding” or “encoding”, followed by a colon, space and the
Encoding name or alias.

Now, according to the Ruby documentation, the Vim modeline shown above
invalid as a Ruby “magic comment” line. It does work, however. Ruby
picks up the specified encoding just fine (only tried with Ruby 1.9.3
and 2.0.0).

So, am I to trust the book or the documentation?

Free Magick 
Free Magick Spell

No one knows the correct rules about the “coding comment” line?

On Tue, Feb 25, 2014 at 12:25 AM, Claus Folke B.
[email protected]wrote:

No one knows the correct rules about the “coding comment” line?

Posted via

Your Vim-compatible modeline does work; so I think there is just an
in the Ruby documentation.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs