[ruby-core:113911] [Ruby master Bug#19733] Kernel#Rational does not accept prefix 0
From:
"mame (Yusuke Endoh) via ruby-core" <ruby-core@...>
Date:
2023-06-15 00:57:19 UTC
List:
ruby-core #113911
Issue #19733 has been updated by mame (Yusuke Endoh).
Status changed from Open to Feedback
"Confusing" is not nessecarily 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
There may be room for discussion to make `Kernel#Rational` accept 0x10, though I personally don't need it. An explanation of a use case would help the discussion.
----------------------------------------
Bug #19733: Kernel#Rational does not accept prefix 0
https://bugs.ruby-lang.org/issues/19733#change-103563
* 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/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/