LoginSignup
6
4

More than 5 years have passed since last update.

Ruby 2.4.0の新機能 「String supports Unicode case mappings」 を試す

Last updated at Posted at 2016-08-02

先日Ruby2.4.0-preview1がリリースされましたね。

大きな機能変更の一つとして、String supports Unicode case mappingsがあります。要するに、upcase、 downcase、swapcase、capitalizeがunicode文字に対応したということです。

試しにRuby2.4.0-preview1で、以下の文字をswapcaseしてみました。

p 'ⅵ'.swapcase
p 'Ⅸ'.swapcase
p 'Å'.swapcase # オングストローム
p 'a'.swapcase # 全角小文字
p 'A'.swapcase # 全角大文字

以下が結果です。

"Ⅵ" # 2.3.0では "ⅵ"
"ⅸ" # 2.3.0では"Ⅸ"
"å" # 2.3.0では "Å"
"A" # 2.3.0では "a"
"a" # 2.3.0では "A"

unicode文字でも変換できました。
あんまり使う機会なさそうですけど・・・

6
4
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4