Ruby - UTF-8 file encoding

前端 未结 1 1467
太阳男子
太阳男子 2020-12-23 20:43

We all know the \"magical\"

# encoding: utf-8

line. But I\'ve seen several other alternative notations, some of them pretty wild. Do you kn

相关标签:
1条回答
  • 2020-12-23 21:09

    No, there are not "exactly 3 ways" to specify the 'magic comment' -- there are an infinite number of them. Any comment on the first line that contains coding: will work, according to JEG2:

    ... the preferred way to set your source Encoding ... it's called a magic comment. If the first line of your code is a comment that includes the word coding, followed by a colon and space, and then an Encoding name, the source Encoding for that file is changed to the indicated Encoding.

    So, any of these should work:

    # coding: UTF-8
    # encoding: UTF-8
    # zencoding: UTF-8
    # vocoding: UTF-8
    # fun coding: UTF-8
    # decoding: UTF-8
    # 863280148705622662 coding: UTF-8 0072364213
    # It was the night before Christmas and all through the house, not a creature was coding: UTF-8, not even with a mouse.
    
    0 讨论(0)
提交回复
热议问题