From: Brian Candler Date: 2009-11-24T01:03:50+09:00 Subject: Re: More on psuedo arrays; Better way? Ralph Shnelvar wrote: > Isn't there a significant cost in the overhead of doing the > string substitution > "x#{rand(i % N_X_METHODS)]" > a million times? It won't be significant unless you build your application, profile it, and find that this is the bottleneck. I'd say this is highly unlikely, and in any case, I doubt the final application will be calling methods at random. Ruby apps are building and throwing away objects all the time. Did you realise, for example, that a loop containing puts "hello" creates a new string object every iteration? This is normal. Strings are mutable, and Ruby has no way of knowing that you haven't mutated the last one it created, so it has to create a fresh one each time. As for x.send("x#{rand(i % N_X_METHODS)]".to_sym) vs x.send("x#{rand(i % N_X_METHODS)]") - they both do the same. If given a String argument, send will convert it to a symbol itself. -- Posted via http://www.ruby-forum.com/.