I'm on Rails 4 and Ruby 1.9.3
I use "strange" characters very often, so I have to declare UTF-8 encoding at the top of all .rb files.
Is there any way to set UTF-8 as the default encoding for Ruby 1.9.3?
I've tried all answers, but when running
`block in trace_on': invalid byte sequence in US-ASCII (ArgumentError)
To change the source encoding (i.e. the encoding your actual written source code is in), you have to use the magic comment currently:
# encoding: utf-8
It is not enough to either set the internal encoding (the encoding of the internal string representation after conversion) or the external encoding (the assumed encoding of read files). You actually have to set the magic encoding comment on top of files to set the source encoding.
As for encoding defaults:
Thus, if you use Ruby 2.0, you could skip the encoding comment and correctly assume UTF-8 encoding everywhere by default.