Forum: Ruby Source/script encoding (magic line)

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

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?
71033b58edd271e5b62ce513eb9d7dfe?d=identicon&s=25 Alli Murrieta (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>
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

> 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.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.