From: Ralph Shnelvar Date: 2009-11-23T00:19:26+09:00 Subject: Re: Pseudo array for Rails migration RK> 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. RK> What stops you from doing RK> N_X = 20 # size of pseudo array RK> class CreatePeople < ActiveRecord::Migration RK> create_table :people do |t| RK> t.string :first_name , :null => false RK> . RK> . RK> . RK> N_X.times do |i| RK> t.integer(("x%02d" % i).to_sym) RK> end RK> t.timestamps RK> end RK> end RK> ? Btw, having columns with indexes in their name is considered bad RK> schema design because you either could normalize it into another table RK> and join or provide more meaningful names instead of "x02" if it is used RK> as a placeholder. My 0.02EUR. RK> Kind regards First of all, I'm a noob. I should have said that. Thus your solution (1) Makes sense. (2) Explains a lot about Ruby. For both I thank you. In terms of normalizing the database, I ran some timing tests and normalizing it slows me down a couple of orders of magnitude. I'm willing to live with the lack of purity for the sake of performance.