From: Ralph Shnelvar Date: 2009-11-24T00:30:56+09:00 Subject: Re: More on psuedo arrays; Better way? MLK> x.send("x#{rand(i % N_X_METHODS)]".to_sym)) MLK> You don't need m at all. Isn't there a significant cost in the overhead of doing the string substitution "x#{rand(i % N_X_METHODS)]" a million times? >> Is there a more Ruby-ish way to do >> anything else in the code, above? MLK> Yes: use operators to make X look like a real array. MLK> class X MLK> def []=(i, arg) MLK> puts "Hi " + i.to_s + arg.to_s MLK> end MLK> end MLK> N_X_METHODS = 20 MLK> 10.times do |i| MLK> x = X.new # should this be outside the loop? MLK> x[rand(i % N_X_METHODS)] = i MLK> end That is very very cool. Thank you.