10. 文字列内式のRefinement
class A; def to_s; "a"; end; end
module B
refine A do
def to_s; "b"; end
end
end
class C
using B
def x
A.new.to_s #=> "b"
"#{A.new}" #=> "b" 2.4 では "a"
end
end
10
20. Numeric: coerce内の例外
class A
def coerce(other)
raise 'hoge'
end
end
# Ruby 2.4
1 < A.new
#=> in `<': comparison of Integer with A failed (ArgumentError)
# Ruby 2.5
1 < A.new
#=> in `coerce': hoge (RuntimeError)
20
21. Range: <=>内の例外
class A
def <=>(x)
raise 'hoge'
end
end
# Ruby 2.4
Range.new(A.new, A.new)
#=> in `initialize': bad value for range (ArgumentError)
# Ruby 2.5
Range.new(A.new, A.new)
#=> in `<=>': hoge (RuntimeError)
21
50. バックトレースの順番
標準エラー出力が端末の場合に表示が逆順
(EXPERIMENTAL)
# Ruby 2.4
% ruby /tmp/a.rb
/tmp/a.rb:8:in `c': unhandled exception
from /tmp/a.rb:5:in `b'
from /tmp/a.rb:2:in `a'
from /tmp/a.rb:10:in `<main>'
# Ruby 2.5
% ruby /tmp/a.rb
Traceback (most recent call last):
3: from /tmp/a.rb:10:in `<main>'
2: from /tmp/a.rb:2:in `a'
1: from /tmp/a.rb:5:in `b'
/tmp/a.rb:8:in `c': unhandled exception
50
51. バックトレースの順番
標準エラー出力が端末でなければ従来通り
% ruby /tmp/a.rb
Traceback (most recent call last):
3: from /tmp/a.rb:10:in `<main>'
2: from /tmp/a.rb:2:in `a'
1: from /tmp/a.rb:5:in `b'
/tmp/a.rb:8:in `c': unhandled exception
% ruby /tmp/a.rb 2>&1 | cat
/tmp/a.rb:8:in `c': unhandled exception
from /tmp/a.rb:5:in `b'
from /tmp/a.rb:2:in `a'
from /tmp/a.rb:10:in `<main>'
51
52. configure で拡張ライブラリを強制
通常は環境に応じて自動判別
--with-ext オプションで強制できる
コンパイルできる環境でない場合は make でエラー
% ./configure --with-ext=openssl,+
% make
...
*** Following extensions are not compiled:
openssl:
Could not be configured. It will not be installed.
/misc/tmp/ruby-2.5.0-preview1/ext/openssl/extconf.rb:94
Check ext/openssl/mkmf.log for more details.
*** Fix the problems, then remove these directories and try again
exts.mk:1853: ターゲット 'note' のレシピで失敗しました
make[1]: *** [note] エラー 1
make[1]: ディレクトリ '/misc/tmp/ruby-2.5.0-preview1' から出ます
uncommon.mk:236: ターゲット 'build-ext' のレシピで失敗しました
make: *** [build-ext] エラー 2
52