Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct utf-8 encoding comment line for ruby? [duplicate]

Possible Duplicate:
Ruby - UTF-8 file encoding

I'm using UTF-8 all the way and want to help the ruby interpreter to read my files. Therefore I put # encoding=utf-8 at the start of my ruby code like this:

#!/usr/bin/env ruby
# encoding=utf-8

But now and then, I see other variants: bundle gem NAME inserts # -*- encoding: utf-8 -*- (into NAME.gemspec). The gem magic_encoding uses this line, too.

What is the recommended way?

  • # encoding = utf-8
  • # encoding: utf-8
  • # -*- encoding: utf-8 -*-
like image 418
Johannes Avatar asked Dec 15 '22 17:12

Johannes


2 Answers

Short answer:

# encoding: utf-8

This is a complete answer: Ruby - UTF-8 file encoding

like image 94
pdjota Avatar answered Feb 08 '23 22:02

pdjota


It looks like a fairly relaxed specification for what's acceptable. I've always used:

# encoding: UTF-8

Also acceptable is coding. I can't find a reference on the variants allowed, but so long as your file is being interpreted correctly it should be fine. Check the __ENCODING__ value to be sure it's being picked up.

like image 36
tadman Avatar answered Feb 09 '23 00:02

tadman