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.
-Paul
···
On Thu, 2012-06-14 at 05:54 +0900, Sam Duncan wrote:
On 14/06/12 08:48, Michael Sung wrote:
> I was wondering why this is not being accepted? I get an error stating
> that + is an unknown method.
>
> I defined a Class and 3 methods within the class, and am merely calling
> the methods and trying to add them together for display from one line:
>
>
> m.ClassMethodString + " " + m.ClassMethodString + ": " +
> m.ClassMethodInteger.to_s
>
Please post your class, or even better the entire code =]
No. The easiest fix is to use string interpolation.
···
On Jun 13, 2012, at 14:26 , Paul Sutton wrote:
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 is subjective - but yes, I think string interpolation is in
general a better solution when outputting a string.
···
On Thu, 2012-06-14 at 09:05 +0900, Ryan Davis wrote:
On Jun 13, 2012, at 14:26 , Paul Sutton wrote:
> 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.