Post by John Carter
Thanks!
Sigh! I have just understood another source of my confusion....
unless you specify the -E command line option,
or explicitly set the encoding on every io open....
you get whatever darn external encoding your user happens to set with the LANG environment variable....
so when you read (unless you've set an internal encoding which might trigger a transcoding),
the string is encoding in whatever the environment variable said.
Which can, (on some strange users' box), result in much sadness if you do a regexp match.
Not exactly robust if you expect a largish herd of cats to be running your scripts.
I guess I had the happy (but incorrect) expectation that the default external encoding would be the same as the script encoding (aka the default regexp encoding).
I think I understand it all now... I think.
John,
Here you can find the "git blame" for Rubocop's style check that ensures you don't have these comment any more. Maybe the Git comments will offer some insight
- https://docs.rubocop.org/rubocop/cops_style.html#styleencoding
- https://rubystyle.guide/#utf-8
- https://github.com/rubocop/rubocop/blame/master/lib/rubocop/cop/style/encoding.rb
Lee Hambley
http://lee.hambley.name/
+49 (0) 170 298 5667
For Ruby, there isn't anymore. But for editors, there may be. Most editors can find the right encoding I guess but some old editors may not. So it is still conventional to add an encoding to source code files. Do I add? No.
I got it into my head they were needed, but https://ruby-doc.org/core-3.0.1/Encoding.html#class-Encoding-label-Script+encoding says it's been the default since V2_0
--
John Carter
Phone : (64)(3) 358 6639
Tait Electronics
PO Box 1645 Christchurch
New Zealand
This Communication is Confidential. We only send and receive email on the
basis of the terms set out at www.taitradio.com/email_disclaimer
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
--
https://ismailarilik.com
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
--
John Carter
Phone : (64)(3) 358 6639
Tait Electronics
PO Box 1645 Christchurch
New Zealand
This Communication is Confidential. We only send and receive email on the
basis of the terms set out at www.taitradio.com/email_disclaimer
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>