From: "Jesús Gabriel y Galán" Date: 2009-11-24T00:46:41+09:00 Subject: Re: More on psuedo arrays; Better way? On Mon, Nov 23, 2009 at 4:34 PM, Ralph Shnelvar wrote: > BC> Marnen Laibow-Koser wrote: >>>> Is there a better way to do this? >>> >>> x.send("x#{rand(i % N_X_METHODS)]".to_sym)) > > BC> And you don't need to_sym either. > > This x.send() will be executed a million times. > > Doesn't that have a fairly high overhead?  Won't a million symbols be > generated?  In my case ... with the m array, only 20 symbols would be > generated. > > Does it matter? > > Is it possible to run out of symbols? A symbol is the same object for the same String representation: irb(main):001:0> a = "test" => "test" irb(main):002:0> a.object_id => -605126498 irb(main):003:0> b = "test" => "test" irb(main):004:0> b.object_id => -605140798 irb(main):005:0> a.to_sym.object_id => 87218 irb(main):006:0> b.to_sym.object_id => 87218 So even if you calling to_sym on different string objects many times, only one symbol for each different string will be created. On the other hand, if you call send with the string, I don't know if a symbol is created inside that call or not. Jesus.