Project

General

Profile

Actions

Bug #19087

closed

String#to_c supports multiple "_"

Added by andrykonchin (Andrew Konchin) 3 months ago. Updated about 2 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:110523]

Description

I've noticed a minor inconsistent behaviour of String#to_c method. It does not treat a sequence of _ character as an end of meaningful characters:

"123".to_c # => (123+0i)
"12_3".to_c # => (123+0i)
"12__3".to_c # => (123+0i)
"12___3".to_c # => (123+0i)

Similar methods #to_i and #to_r treat multiple _ in a different way - they just ignore characters after it:

"12__3".to_i # => 12
"12__3".to_r # => (12/1)

I would expect #to_c to behave similarly.


$ ruby -v
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin21]
Actions #1

Updated by andrykonchin (Andrew Konchin) 3 months ago

  • Subject changed from String#to_c supports "_" to String#to_c supports multiple "_"
Actions #2

Updated by nobu (Nobuyoshi Nakada) 3 months ago

  • Tracker changed from Misc to Bug
  • Backport set to 2.7: REQUIRED, 3.0: REQUIRED, 3.1: REQUIRED
Actions #5

Updated by nobu (Nobuyoshi Nakada) about 2 months ago

  • Status changed from Open to Closed

Applied in changeset git|c0dc717c45fc3abc64a337c3481bc4555b675d87.


[Bug #19087] Disallow successive underscores in Complex string

Updated by nagachika (Tomoyuki Chikanaga) about 2 months ago

  • Backport changed from 2.7: REQUIRED, 3.0: REQUIRED, 3.1: REQUIRED to 2.7: REQUIRED, 3.0: REQUIRED, 3.1: DONTNEED

I agree that the new behavior is consistent and preferable, but I don't think it should be fixed on the stable branches.
If there are any troubles on the real world applications with this issue, please let me know.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like1Like0Like0Like0