# Beginning a variable name with a number

**URL:** <https://www.ruby-forum.com/t/beginning-a-variable-name-with-a-number/112959>\
**Category:** Ruby\
**Created:** [August 25, 2007, 12:20am UTC](https://www.ruby-forum.com/t/beginning-a-variable-name-with-a-number/112959 "2007-08-25T00:20:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eggie5](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7c8e57/32.png) [@eggie5](https://www.ruby-forum.com/u/eggie5)\
**Post date:** [August 25, 2007, 12:20am UTC](https://www.ruby-forum.com/t/beginning-a-variable-name-with-a-number/112959/1 "2007-08-25T00:20:48Z")

</div>

I have a symbol that I need to name with a number as the first  
character, but that’s invalid ruby syntax. e.g.:

t.column :\_3g2, :integer

How can I somehow escape the ‘3’ so I don’t have the use the ‘\_’ in  
the variable name?

---

<div class="post-metadata">

**Author:** ![eggie5](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7c8e57/32.png) [@eggie5](https://www.ruby-forum.com/u/eggie5)\
**Post date:** [August 25, 2007, 12:26am UTC](https://www.ruby-forum.com/t/beginning-a-variable-name-with-a-number/112959/2 "2007-08-25T00:26:13Z")

</div>

eggie5 wrote:

> I have a symbol that I need to name with a number as the first  
> character, but that’s invalid ruby syntax. e.g.:
> 
> t.column :\_3g2, :integer
> 
> How can I somehow escape the ‘3’ so I don’t have the use the ‘\_’ in  
> the variable name?

As far as I know there is no way to begin a variable name with a number  
(I assume simply because it would be PITA with all the exceptions to it,  
as what would be Integer literals, such as 0xff).  
A symbol however can, using the :"" syntax: :“1-2-3 mine”.class # =\>  
Symbol

Regards  
Stefan

---

<div class="post-metadata">

**Author:** ![eggie5](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7c8e57/32.png) [@eggie5](https://www.ruby-forum.com/u/eggie5)\
**Post date:** [August 25, 2007, 12:28am UTC](https://www.ruby-forum.com/t/beginning-a-variable-name-with-a-number/112959/3 "2007-08-25T00:28:49Z")

</div>

On 8/24/07, eggie5 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have a symbol that I need to name with a number as the first  
> character, but that’s invalid ruby syntax. e.g.:
> 
> t.column :\_3g2, :integer

You can quote the symbol …

t.column :“3g2”, :integer

Blessings,  
TwP

---

<div class="post-metadata">

**Author:** ![eggie5](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7c8e57/32.png) [@eggie5](https://www.ruby-forum.com/u/eggie5)\
**Post date:** [August 25, 2007, 10:24am UTC](https://www.ruby-forum.com/t/beginning-a-variable-name-with-a-number/112959/4 "2007-08-25T10:24:46Z")

</div>

> You can quote the symbol …
> 
> t.column :“3g2”, :integer

In general, isn’t the need to store a number in a database column name  
an  
example of a “missing abstraction”? Shouldn’t a database (or whatever  
t.column fronts) store its numbers as data?
