Beginning a variable name with a number

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?

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

On 8/24/07, eggie5 [email protected] 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

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?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs