Project

General

Profile

Actions

Feature #17520

closed

Allow symbols starting with number, e.g. :2_weeks

Added by dorianmariefr (Dorian Marié) over 3 years ago. Updated about 3 years ago.

Status:
Feedback
Assignee:
-
Target version:
-
[ruby-core:101984]

Description

For instance:

p({ 2_weeks: 1 })

results in:

a.rb:1: trailing `_' in number
p({ 2_weeks: 1 })
a.rb:1: syntax error, unexpected local variable or method, expecting =>
p({ 2_weeks: 1 })

and

p({ :2_weeks => 1 })

results in:

a.rb:1: trailing `_' in number
p({ :2_weeks => 1 })
a.rb:1: syntax error, unexpected integer literal, expecting literal content or terminator or tSTRING_DBEG or tSTRING_DVAR

I'm not sure if it's doable as ruby thinks I'm writing a number, just wondering if that could be possible to start a symbol with a number

(I know { "2_weeks": 1 } works, that's what I'm using instead)

Actions #1

Updated by dorianmariefr (Dorian Marié) over 3 years ago

  • Description updated (diff)

Updated by marcandre (Marc-Andre Lafortune) over 3 years ago

  • Status changed from Open to Feedback

You may not know that:

p({ '2_weeks': 1 })
# => prints {:"2_weeks"=>1}

Such symbols being quite rare, I believe this solution should be enough.

Actions #3

Updated by jeremyevans0 (Jeremy Evans) about 3 years ago

  • Tracker changed from Bug to Feature
  • ruby -v deleted (ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19])
  • Backport deleted (2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN)
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0