Forum: Ruby Source/script encoding (magic line)

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
5ee673df36bc248d4d12b9978b1b83a8?d=identicon&s=25 Claus Folke B. (cfbrobak)
on 2014-02-12 09:21
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?
9563810f3e7ac7e918962592df0d54e6?d=identicon&s=25 Alli M. (allison93m)
on 2014-02-18 07:58
<a href="" title="Free
Magick Spell" name="Free Magick Spell"><img
src="" alt="Free Magick
Spell" title="Free Magick Spell" /><br>Free Magick Spell</a>
5ee673df36bc248d4d12b9978b1b83a8?d=identicon&s=25 Claus Folke B. (cfbrobak)
on 2014-02-25 07:25
No one knows the correct rules about the "coding comment" line?
4fd6f6b507aa3ac75b6cb8ab26fde1c5?d=identicon&s=25 Eric C. (echristopherson)
on 2014-02-26 03:38
(Received via mailing list)
On Tue, Feb 25, 2014 at 12:25 AM, Claus Folke Brobak

> 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 topic is locked and can not be replied to.