From: Alex Young Date: 2006-08-10T21:17:04+09:00 Subject: Re: extending String call with a #copy!(n) Alex Young wrote: > Une b�vue wrote: >> i've allready extendy String class by a #copy(n) like that : >> >> class String >> def copy(n) >> out="" >> (1..n).each {|i| out+=self} >> return out >> end >> end >> >> however i'd like to extend also String with a #copy!(n) (in place which >> would work like that : >> >> "*".copy!(4) >> # => "****" >> >> the prob is to affect self ??? > > Use << (or concat). > or sub!. class String def copy!(n) self.sub!(self, self*n) end end -- Alex