From: pharrington Date: 2009-12-06T16:56:01+09:00 Subject: Re: Why doesn't Ruby "compile" strings? On Dec 5, 9:29 pm, Marnen Laibow-Koser wrote: > 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-Koserhttp://www.marnen.org > mar...@marnen.org > -- > Posted viahttp://www.ruby-forum.com/. No, two Strings get created here: one with .to_s and the other with .upcase