Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Unfortunately, it is impossible for a machine to upcase/downcase/capitalize properly. It needs way too much contextual information for a computer to understand.</p> <p>That's why Ruby's <code>String</code> class only supports capitalization for ASCII characters, because there it's at least <em>somewhat</em> well-defined.</p> <p>What do I mean by "contextual information"?</p> <p>For example, to capitalize <code>i</code> properly, you need to know which language the text is in. English, for example, has only two <code>i</code>s: capital <code>I</code> without a dot and small <code>i</code> with a dot. But Turkish has four <code>i</code>s: capital <code>I</code> without a dot, capital <code>İ</code> with a dot, small <code>ı</code> without a dot, small <code>i</code> with a dot. So, in English <code>'i'.upcase # =&gt; 'I'</code> and in Turkish <code>'i'.upcase # =&gt; 'İ'</code>. In other words: since <code>'i'.upcase</code> can return two different results, depending on the language, it is obviously impossible to correctly capitalize a word without knowing its language.</p> <p>But Ruby doesn't know the language, it only knows the encoding. Therefore it is impossible to properly capitalize a string with Ruby's built-in functionality.</p> <p>It gets worse: even <em>with</em> knowing the language, it is sometimes impossible to do capitalization properly. For example, in German, <code>'Maße'.upcase # =&gt; 'MASSE'</code> (<em>Maße</em> is the plural of <em>Maß</em> meaning <em>measurement</em>). However, <code>'Masse'.upcase # =&gt; 'MASSE'</code> (meaning <em>mass</em>). So, what is <code>'MASSE'.capitalize</code>? In other words: correctly capitalizing requires a full-blown Artificial Intelligence.</p> <p>So, instead of sometimes giving the wrong answer, Ruby chooses to sometimes give no answer <em>at all</em>, which is why non-ASCII characters simply get ignored in downcase/upcase/capitalize operations. (Which of course also reads to wrong results, but at least it's easy to check.)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload