Iñaki Baz Castillo wrote: > El Domingo, 6 de Diciembre de 2009, Kirk Haines escribió: >> > 1.upto(4) do >> > puts Benchmark.realtime { 1.upto(500000) {|i| 'hello_world'.upcase >> > the strings appearing in the script? >> >> This is because when you are using the constant, you are referring to the >> same object every time. >> >> When you are using the string literals, the interpreter doesn't know what >> you are going to do with that string literal, so it's not really safe for >> it to assume that it can use a single ruby object to represent all >> instances of it. > > Why not? It's obviously a string writen in the script, with no variables > into > it and so... Irrelevant. Ruby strings are mutable, remember? In other words, if I do a = 'hello' b = 'hello' a.upcase! then a is 'HELLO' while b is 'hello'. This would not work as expected if both 'hello' strings were the same object. It works with symbols largely because symbols are immutable. Best, -- MarnenLaibow-Koser http://www.marnen.org marnen / marnen.org -- Posted via http://www.ruby-forum.com/.