Creating tables with "variable" field names

Discussion in 'Ruby' started by Yaron Kretchmer, Feb 27, 2008.

  1. Hi All
    I'm slowly ramping up on Ruby (Ex-PERL'y), and have the following
    question:
    *) I'd like to create a table , but with column names which are not
    fixed. So instead of doing

    <Code>
    def self.up
    create_table mytable do |t|
    t.column :field1, :string
    t.column :field2, :stringI'd like to do
    </Code>

    I'd like to do

    <Code>
    var1 = "field1"
    var2 = "field2"
    def self.up
    create_table mytable do |t|
    t.column $var1, :string
    t.column $var2, :stringWhat is the correct syntax for doing that?
    </Code>
    Best Regards
    Kretch
    --
    Posted via http://www.ruby-forum.com/.
     
    Yaron Kretchmer, Feb 27, 2008
    #1
    1. Advertisements

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. Bob
    Replies:
    1
    Views:
    564
    Lucas Tam
    Jul 30, 2004
  2. wanwan
    Replies:
    3
    Views:
    590
    Alex Martelli
    Oct 14, 2005
  3. News123
    Replies:
    2
    Views:
    709
    John Machin
    Nov 26, 2008
  4. Peter Buckley
    Replies:
    5
    Views:
    428
    matt neuburg
    Feb 27, 2009
  5. bdz
    Replies:
    3
    Views:
    174
    John W. Krahn
    Jul 16, 2006
  6. Peter Jamieson

    Making variable field names

    Peter Jamieson, Jan 18, 2008, in forum: Perl Misc
    Replies:
    1
    Views:
    140
    Peter Jamieson
    Jan 19, 2008
  7. Sound
    Replies:
    2
    Views:
    752
    Randy Webb
    Sep 28, 2006
  8. jr
    Replies:
    3
    Views:
    695
Loading...