beginning a variable name with a number

Discussion in 'Ruby' started by eggie5, Aug 24, 2007.

  1. eggie5

    eggie5 Guest

    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, Aug 24, 2007
    #1
    1. Advertising

  2. 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/.
     
    Stefan Rusterholz, Aug 24, 2007
    #2
    1. Advertising

  3. eggie5

    Tim Pease Guest

    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
     
    Tim Pease, Aug 24, 2007
    #3
  4. eggie5

    Phlip Guest

    > 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
     
    Phlip, Aug 25, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bobby Chamness
    Replies:
    2
    Views:
    2,401
    Joe Smith
    Apr 22, 2007
  2. mfglinux
    Replies:
    11
    Views:
    707
    Roberto Bonvallet
    Sep 12, 2007
  3. Jesse B.
    Replies:
    9
    Views:
    236
    Jesse B.
    Mar 27, 2010
  4. Jesse B.
    Replies:
    27
    Views:
    245
    thunk
    Apr 3, 2010
  5. David Filmer
    Replies:
    19
    Views:
    248
    Kevin Collins
    May 21, 2004
Loading...

Share This Page