Revise Rational#quo documentation #2143
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Rational#quo のドキュメントを修正します。
ここで「other に Float を指定した場合は、計算結果を Float で返します。ただし 0 以外の整数に等しい場合は Rational で返します。」と書かれています。
ですが、「ただし 0 以外の整数に等しい場合は Rational で返します。」は現在の挙動と異なるようでした。現在はotherがFloatの場合は戻り値もFloatになっています。
「ただし 0 以外の整数に等しい場合は Rational で返します。」というのは、1.9.3と2.0.0のみの挙動のようです。
$ docker run -it --rm rubylang/all-ruby env ALL_RUBY_SINCE=ruby-1.8.0 ./all-ruby -rrational -e 'p Rational(3, 4) / 2.0' ruby-1.8.0 0.375 ... ruby-1.9.2-p330 0.375 ruby-1.9.3-preview1 (3/8) ... ruby-2.0.0-p648 (3/8) ruby-2.1.0-preview1 0.375 ... ruby-2.7.0 0.375
どうやら色々あって変更がrevertされたようです。
https://bugs.ruby-lang.org/issues/5515
そのため、ドキュメントの記述も実際の挙動に合わせて修正しています。
なお、サンプルコードには実際の挙動に合った戻り値が書かれているので修正は不要でした ✔️