Forum: Ruby Source/script encoding (magic line)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
58c27bbf5c57037cc3579ca8f3082176?d=identicon&s=25 Claus Folke Brobak (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
file.

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
http://www.ruby-doc.org/core-2.0.0/Encoding.html
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
is
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?
71033b58edd271e5b62ce513eb9d7dfe?d=identicon&s=25 Alli Murrieta (allison93m)
on 2014-02-18 07:58
<a href="http://www.changeyourlifespells.com/about.php" title="Free
Magick Spell" name="Free Magick Spell"><img
src="http://www.real-wishes.com/images/wish-3.jpg" alt="Free Magick
Spell" title="Free Magick Spell" /><br>Free Magick Spell</a>
58c27bbf5c57037cc3579ca8f3082176?d=identicon&s=25 Claus Folke Brobak (cfbrobak)
on 2014-02-25 07:25
No one knows the correct rules about the "coding comment" line?
Abdb670e1c130f96f947a94d03c02efa?d=identicon&s=25 Eric Christopherson (echristopherson)
on 2014-02-26 03:38
(Received via mailing list)
On Tue, Feb 25, 2014 at 12:25 AM, Claus Folke Brobak
<lists@ruby-forum.com>wrote:

> No one knows the correct rules about the "coding comment" line?
>
> --
> Posted via http://www.ruby-forum.com/.
>

Your Vim-compatible modeline does work; so I think there is just an
error
in the Ruby documentation.
This topic is locked and can not be replied to.