[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

beginning a variable name with a number

eggie5

8/24/2007 10:19:00 PM

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?

3 Answers

Stefan Rusterholz

8/24/2007 10:26:00 PM

0

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
--
Posted via http://www.ruby-....

Tim Pease

8/24/2007 10:28:00 PM

0

On 8/24/07, eggie5 <eggie5@gmail.com> 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

Phlip

8/25/2007 8:24:00 AM

0

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

--
Phlip