From: Robert Klemme Date: 2009-11-22T23:55:06+09:00 Subject: Re: Pseudo array for Rails migration On 22.11.2009 15:06, Ralph Shnelvar wrote: > Consider > > > N_X = 20 # size of pseudo array > > class CreatePeople < ActiveRecord::Migration > > create_table :people do |t| > t.string :first_name , :null => false > . > . > . > t.integer :x00 > t.integer :x01 > t.integer :x02 > . > . > . > t.integer :x18 > t.integer :x19 > > > t.timestamps > end > end > > > > What is the (best) way of generating the "t.integer :xYY" (where YY is > 00 through 19, inclusive) which is dependent on N_X. What stops you from doing N_X = 20 # size of pseudo array class CreatePeople < ActiveRecord::Migration create_table :people do |t| t.string :first_name , :null => false . . . N_X.times do |i| t.integer(("x%02d" % i).to_sym) end t.timestamps end end ? Btw, having columns with indexes in their name is considered bad schema design because you either could normalize it into another table and join or provide more meaningful names instead of "x02" if it is used as a placeholder. My 0.02EUR. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/