Please post your class, or even better the entire code =]
And the actual error… most likely your function isn’t returning a
string. The error should tell you want class ‘+’ is not defined in. For
example, if your method returns nil you’ll get:
NoMethodError: undefined method `+’ for nil:NilClass
Easiest fix would be to call to_s on the return value of your methods
(e.g. m.ClassMethodString.to_s) but that might merely cover-up some
problem with your method’s return value.
Easiest fix would be to call to_s on the return value of your methods
(e.g. m.ClassMethodString.to_s) but that might merely cover-up some
problem with your method’s return value.
No. The easiest fix is to use string interpolation.
Easiest is subjective - but yes, I think string interpolation is in
general a better solution when outputting a string.
Easiest fix would be to call to_s on the return value of your methods
(e.g. m.ClassMethodString.to_s) but that might merely cover-up some
problem with your method’s return value.
No. The easiest fix is to use string interpolation.
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.
…
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”
Thank you for the tracer analysis. I did some time benchmarks and it
seems to be about 30% faster. I agree completely that interpolation is
better.