Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > beginning a variable name with a number

Reply
Thread Tools

beginning a variable name with a number

 
 
eggie5
Guest
Posts: n/a
 
      08-24-2007
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?

 
Reply With Quote
 
 
 
 
Stefan Rusterholz
Guest
Posts: n/a
 
      08-24-2007
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-forum.com/.

 
Reply With Quote
 
 
 
 
Tim Pease
Guest
Posts: n/a
 
      08-24-2007
On 8/24/07, 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


You can quote the symbol ...

t.column :"3g2", :integer

Blessings,
TwP

 
Reply With Quote
 
Phlip
Guest
Posts: n/a
 
      08-25-2007
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
return number of spaces at the beginning of a line Jesse B. Ruby 27 04-03-2010 02:26 PM
index of string from beginning of line vs beginning of file Jesse B. Ruby 9 03-27-2010 04:04 PM
"Variable variable name" or "variable lvalue" mfglinux Python 11 09-12-2007 03:08 AM
adding a variable name to a hash to name is part of the variable name Bobby Chamness Perl 2 04-22-2007 09:54 PM
How do I scope a variable if the variable name contains a variable? David Filmer Perl Misc 19 05-21-2004 03:55 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57