beginning a variable name with a number

E

eggie5

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?
 
S

Stefan Rusterholz

eggie5 said:
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
 
T

Tim Pease

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
 
P

Phlip

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top