From: "Einar Magnús Boson" Date: 2008-11-18T11:33:32+09:00 Subject: Re: let my custom defined class convert to string? On 18.11.2008, at 02:01 , Jonathan Rochkind wrote: > Is there any way I can make it so my custom-defined class can be > automatically converted to a string? > > I have a #to_s method in it. > > So it works when I do something like "#{var_of_my_class} foo". It > calls > #to_s there. > > But if I try instead "some string" + var_of_my_class, then ruby > complains that it can't convert MyClass to a string. > > Is there anything I can do so my class will always be converted > properly > to a String by ruby, in all cases, so client code can really use it > just > like a string? > > Jonathan > -- > Posted via http://www.ruby-forum.com/. > class MyClass < String end Einar Magnús Boson +354-661 1649 einarmagnus@tistron.se einar.boson@gmail.com