
Issue #19733 has been updated by sawa (Tsuyoshi Sawada). mame (Yusuke Endoh) wrote in #note-2:
"Confusing" is not necessarily a bug. What Kernel#Rational accepts is clearly stated in the documentation in BNF style.
https://docs.ruby-lang.org/en/master/Kernel.html#method-i-Rational
I have read that documentation, and thought that perhaps someone is going to mention. That documentation is broken as It does not mention the fact that the denominator can take a fractional part. ```ruby Rational("1/1.2") # => (5/6) ``` According to the documentation you cited, the expression above should raise an argument error, contrary to fact. So, that documentation is not reliable any way. ---------------------------------------- Bug #19733: Kernel#Rational does not accept prefix 0 https://bugs.ruby-lang.org/issues/19733#change-103564 * Author: sawa (Tsuyoshi Sawada) * Status: Feedback * Priority: Normal * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- `Integer` and `Rational` literals accept prefix `0`. There is no difference in this respect. ```ruby 0b10 # => 2 0b10r # => (2/1) ``` However, when it comes to `Kernel#Integer` and `Kernel#Rational`, the former accepts prefix `0` while the latter does not. This is confusing. And as I do not see any reason they should behave differently, I think it is a bug. ```ruby Integer("0b10") # => 2 Rational("0b10") # !> ArgumentError ``` -- https://bugs.ruby-lang.org/