💭
[Bug #21864] nil を数値に変換できなかった場合のエラーメッセージの改善
[Bug #21864] Inconsistencies in type coercion error messages for integers
- 数値を受け取るメソッドに対して数値以外を渡すと次のようなエラーメッセージが出力される
[1, 2]["0"]
# => error: no implicit conversion of String into Integer (TypeError)
[1, 2][false]
# => error: no implicit conversion of false into Integer (TypeError)
- しかし次のように
nilを渡したときには上記とは異なるエラーメッセージになる-
~ of ~ into ~が~ from ~ to ~だったりintegerが大文字だったり小文字だったり
-
[1, 2][nil]
# => error: no implicit conversion from nil to integer (TypeError)
-
nilの場合も最初のエラーメッセージと同じようなフォーマットにしたいという内容のチケット - 正直なところ個人的にはどっちでも気にはならないんですが英語圏の人とかはこのあたり気になったりするんですかね?
- これは開発版の Ruby 4.1-dev で次のように対応されました
[1, 2][nil]
# Ruby 4.0 => error: no implicit conversion from nil to integer (TypeError)
# Ruby 4.1 => error: no implicit conversion of nil into Integer (TypeError)
Discussion