[ruby-core:80098] [Ruby trunk Bug#13105] `String#to_f` and `String#to_r` don't stop at successive underscores

From: nobu@...
Date: 2017-03-13 05:11:22 UTC
List: ruby-core #80098
Issue #13105 has been updated by Nobuyoshi Nakada.

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

----------------------------------------
Bug #13105: `String#to_f` and `String#to_r` don't stop at successive underscores
https://bugs.ruby-lang.org/issues/13105#change-63523

* Author: Nobuyoshi Nakada
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
* Target version: 2.5
* ruby -v: r57270
* Backport: 2.2: REQUIRED, 2.3: REQUIRED, 2.4: REQUIRED
----------------------------------------
`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?

```ruby
"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
```



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next