From: Marnen Laibow-Koser Date: 2009-12-06T11:29:26+09:00 Subject: Re: Why doesn't Ruby "compile" strings? Iñaki Baz Castillo wrote: > El Domingo, 6 de Diciembre de 2009, Marnen Laibow-Koser escribió: >> > Is it imposible due to the design of Ruby? >> >> It's not impossible at all: just use symbols instead of strings. > > What do you mean with symbols? do you mean using the following?: > > puts Benchmark.realtime { 1.upto(500000) {|i| > :"hello_world".to_s.upcase } } > > I expect the same results as when converting the symbol to string (to_s) > Ruby > would generate a new string for each iteration, am I wrong? Only one per iteration -- 'HELLO WORLD'. Your original implementation would generate two new String objects for each iteration. > > Thanks. Best, --  Marnen Laibow-Koser http://www.marnen.org marnen@marnen.org -- Posted via http://www.ruby-forum.com/.