From: Ryan Davis Date: 2012-06-14T13:32:07+09:00 Subject: Re: Calling methods, getting string and adding them On Jun 13, 2012, at 21:28 , Ryan Davis wrote: > > On Jun 13, 2012, at 21:24 , Paul Sutton wrote: > >> Easiest is subjective - but yes, I think string interpolation is in >> general a better solution when outputting a string. > > It is measurable by the number of methods called and the number of garbage objects created. Compare: % ruby -rtracer -e '"a" + 1.to_s + "b" + 2.to_s + "c"' #0:-e:1::-: "a" + 1.to_s + "b" + 2.to_s + "c" #0:-e:1:Fixnum:>: "a" + 1.to_s + "b" + 2.to_s + "c" #0:-e:1:Fixnum:<: "a" + 1.to_s + "b" + 2.to_s + "c" #0:-e:1:String:>: "a" + 1.to_s + "b" + 2.to_s + "c" #0:-e:1:String:<: "a" + 1.to_s + "b" + 2.to_s + "c" #0:-e:1:String:>: "a" + 1.to_s + "b" + 2.to_s + "c" #0:-e:1:String:<: "a" + 1.to_s + "b" + 2.to_s + "c" #0:-e:1:Fixnum:>: "a" + 1.to_s + "b" + 2.to_s + "c" #0:-e:1:Fixnum:<: "a" + 1.to_s + "b" + 2.to_s + "c" #0:-e:1:String:>: "a" + 1.to_s + "b" + 2.to_s + "c" #0:-e:1:String:<: "a" + 1.to_s + "b" + 2.to_s + "c" #0:-e:1:String:>: "a" + 1.to_s + "b" + 2.to_s + "c" #0:-e:1:String:<: "a" + 1.to_s + "b" + 2.to_s + "c" 2111 % ruby -rtracer -e '"a#{1}b#{2}c"' #0:-e:1::-: "a#{1}b#{2}c" #0:-e:1:Fixnum:>: "a#{1}b#{2}c" #0:-e:1:Fixnum:<: "a#{1}b#{2}c" #0:-e:1:Fixnum:>: "a#{1}b#{2}c" #0:-e:1:Fixnum:<: "a#{1}b#{2}c"