From: shevegen@... Date: 2019-05-25T22:25:41+00:00 Subject: [ruby-core:92843] [Ruby trunk Bug#15876] 1.to_s.encoding != Encoding.default_internal Issue #15876 has been updated by shevegen (Robert A. Heiler). > which is confusing/annoying especially to users that don't know > how encodings work in ruby. I personally finally switched into UTF-8 (oddly enough, primarily due to emoji and unicode-symbols that can be used for simple indications both on the commandline and www), but I think one problem (for me) was from ruby 1.8.x to later ruby versions that there was not that much documentation available. Judging from your comment encoding may still pose a problem for some ruby users (or potentially new ruby users). Some time ago, I think, jeremy evans wrote a document about symbols, which was added (my apologies if I misremember). If anyone feels like writing some document about encoding in ruby, and how to deal with it ... :) (could be in wiki-style or perhaps gist-github or some other place; I am in no way suggesting that only a single person should do so, it could be a collaborative effort). To the issue at hand, I just tested in irb: 1.to_s.encoding #should be the same as "".encoding # => # "".encoding # => # This is indeed a little surprising (to me). There may be valid reasons for this, perhaps default external encoding, or something like this, but I can see why people may be confused about it. Actually what surprises me is that .to_s on the number leads to US-ASCII encoding by default. I think looking back when I used an ISO-encoding, the most surprising result I had encountered was actually in regards to regexp-engine and encodings used there. I do not remember exactly how I found it, but I think I reported it back then; still not entirely sure how it came, but regexes may also be an area where users may be a little bit confused - so documentation may be of some help. ---------------------------------------- Bug #15876: 1.to_s.encoding != Encoding.default_internal https://bugs.ruby-lang.org/issues/15876#change-78224 * Author: grosser (Michael Grosser) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: 2.6.3 * Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- I ran into strange looking test output when I compared .to_s with an expected text, saying that the encoding was different, which is confusing/annoying especially to users that don't know how encodings work in ruby. 1.to_s.encoding should be the same as "".encoding -- https://bugs.ruby-lang.org/ Unsubscribe: