From: dblack@... Date: 2002-12-09T11:43:15+09:00 Subject: Re: [YANQ] -yet another (ruby) newbie question -string#concat Hi -- On Mon, 9 Dec 2002, [iso-8859-1] "Pe�a, Botp" wrote: > Hello Ruby Friends, > > >From now on, I'll prefix my questions w YANQ (yet another (ruby) newbie > question) so it would be easier for you to delete (in case :-). ruby + newbie == nuby :-) > My YANQotd is regarding string#concat. A sample code and output would be > good to illustrate: > > C:\family\ruby>type a1.rb > fn = "bot" > ln = "pen" > name = fn.concat(ln) > > print "first name: ", fn > puts > print "last name : ", ln > puts > print "full name : ", name > > C:\family\ruby>ruby a1.rb > first name: botpen > last name : pen > full name : botpen > > > I noticed that concat modified fn. I looked for other concat methods but > couldn't find one (but the + op). I was hoping that there would be a concat! > and concat pair (like chop!/chop and chomp!/chomp). > > Maybe string#concat! was deprecated for "+"? My concern is that (as a String#concat is a synonym for String#<<, and since it modifies the object, a concat! version wouldn't make sense. You can indeed use String#+ if you want to create a new string instead of modifying the old one. > newbie), I'm trying to avoid methods with "!" (like chomp!/chop!) so I have > less to worry/know. My strategy was working and I was actually coding w > breeze... until I bump.. :-( I think in the long run that strategy will give you *more* to worry about :-) Don't feel you have to avoid ! methods; they're a normal part of Ruby, and not particularly complicated. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav