Ruby 2.7 の変更点 - Unicode 12.1 / $SAFE と汚染オブジェクト

Ruby 2.7 アドベントカレンダーの11日目の記事です。

qiita.com

Unicode 12.1

Unicode 12.1 に対応しました(2.6.3 から対応してます)。

Ruby 2.6.2

p "".unicode_normalize(:nfkd) #=> "\u32FF" 

Ruby 2.7

p "".unicode_normalize(:nfkd) #=> "令和" 

$SAFE と汚染オブジェクト

$SAFE の使用でwarning が出るようになりました。3.0 では $SAFE は普通のグローバル変数になるようです。

$SAFE = 1 #=> warning: $SAFE will become a normal global variable in Ruby 3.0 p $SAFE #=> 1 #=> warning: $SAFE will become a normal global variable in Ruby 3.0 

また、汚染まわりのメソッドも機能しなくなり(常に汚染されてないとみなされる)、verbose モードで warning が出力されます。

Ruby 2.6

$VERBOSE = true s = "hoge".taint s.tainted? #=> true 

Ruby 2.7

$VERBOSE = true s = "hoge".taint #=> warning: Object#taint is deprecated and will be removed in Ruby 3.2. s.tainted? #=> false #=> warning: Object#tainted? is deprecated and will be removed in Ruby 3.2. 

3.0 で verbose じゃなくても warning が表示されるようになり、3.2 でメソッドが削除されるようです。

コメントを書く

Ruby 2.7 の変更点 - Unicode 12.1 / $SAFE と汚染オブジェクト

プロフィール
注目記事