From: Gary Wright Date: 2008-01-31T09:06:41+09:00 Subject: Re: ruby wish-list On Jan 30, 2008, at 6:00 PM, Chad Perrin wrote: > On Thu, Jan 31, 2008 at 04:34:49AM +0900, Roger Pack wrote: >> I know this is controversial, but I wish that if you did >> string_1 + object_2 (or any object) that it would just call .to_s on >> object_2 (instead of having to write it explicitly). I hate >> having to >> write extra .to_s's (even if it avoids ambiguity). That's just >> me, but >> hey :) > >> irb > irb(main):001:0> obj = Object.new > => # > irb(main):002:0> puts obj > # > => nil > irb(main):003:0> puts obj.to_s > # > => nil > > Seems like it already does what you want. What am I missing? I think Roger is saying that String#+ should call to_s on its argument. String#+ already calls to_str on its argument: >> a = Object.new => # >> class <> def to_str >> 'object' >> end >> end => nil >> puts 'text+' + a text+object => nil Another approach is to use Array#join instead of String#+: >> ['a', Object.new, 'b'].join => "a#b" Gary Wright