Bug #13105
closed
`String#to_f` and `String#to_r` don't stop at successive underscores
Added by nobu (Nobuyoshi Nakada) almost 8 years ago.
Updated almost 8 years ago.
Description
Integer()
, Float()
and Rational()
errs at successive underscores, and String#to_i
stops the conversion there.
But String#to_f
and String#to_r
continue the conversion like as there were just one underscore.
Is this intentional?
"1_2".to_i #=> 12
"1__2".to_i #=> 1
"1.__2".to_f #=> 1.2
"0.1__2".to_r #=> (3/25) == 0.12
- Subject changed from `String#to_f` and `String#to_r` don't stop successive underscores to `String#to_f` and `String#to_r` don't stop at successive underscores
- Assignee changed from matz (Yukihiro Matsumoto) to nobu (Nobuyoshi Nakada)
We should have more consistency here. to_i
and to_r
should be more restrictive on treating _
.
Namely,
-
_
should be within digits
- only one
_
allowed between digits
Matz.
- Status changed from Assigned to Closed
Applied in changeset r57979.
object.c: make String#to_f consistent with literal
- Status changed from Closed to Open
- Assignee changed from nobu (Nobuyoshi Nakada) to matz (Yukihiro Matsumoto)
- Assignee changed from matz (Yukihiro Matsumoto) to nobu (Nobuyoshi Nakada)
- Status changed from Open to Closed
Applied in changeset r57987.
test_rational.rb: invalid exponent
- Backport changed from 2.2: REQUIRED, 2.3: REQUIRED, 2.4: REQUIRED to 2.2: WONTFIX, 2.3: WONTFIX, 2.4: WONTFIX
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0Like0Like0