BigBinary Blog

We write about Ruby on Rails, React.js, React Native, remote work, open source, engineering and design.

Ruby 2.6 adds support for non-ASCII capital letter

This blog is part of our Ruby 2.6 series.

Ruby 2.6.0 was released on Dec 25, 2018.

Before Ruby 2.6, constant must have a capital ASCII letter as the first character. It means class and module name cannot start with non-ASCII capital character.

Below code will raise class/module name must be CONSTANT exception.

1  class Большойдвоичный
2  end

We can use above non-ASCII character as a method name or variable name though.

Below code will run without any exception

1  class NonAsciiMethodAndVariable
2    def Большойдвоичный
3      Имя = "BigBinary"
4    end
5  end

"Имя" is treated as a variable name in above example, even though first letter(И) is a capital non-ASCII character.

Ruby 2.6

Ruby 2.6 relaxes above mentioned limitation. We can now define constants in languages other than English. Languages having capital letters like Russian and Greek can be used to define constant name.

Below code will run without exception in any Ruby 2.6.

1  class Большойдвоичный
2  end

As capital non-Ascii characters are now treated as constant, below code will raise a warning in Ruby 2.6.

1  irb(main):001:0> Имя = "BigBinary"
2  => "BigBinary"
3  irb(main):002:0> Имя = "BigBinary"
4  (irb):2: warning: already initialized constant Имя
5  (irb):1: warning: previous definition of Имя was here

Above code will run without any warnings on Ruby versions prior to 2.6

Here is relevant commit and discussion for this change.

Rohan Pujari in Ruby 2.6
August 22, 2018
Share

Subscribe to our newsletter