From: Martin DeMello Date: 2003-06-23T03:50:42+09:00 Subject: Re: String#decorate daz wrote: > > "Martin DeMello" wrote: > >> ts wrote: >> >>>>>> "M" == Martin DeMello writes: >> > >> > M> pp = ary.join(",").decorate {|s| "[#{s}]"} >> > M> attrib = title.capitalize.decorate {|t| "\t -- #{author[t]},\"#{t}\""} >> > M> (n*100).to_s.decorate {|p| "#{p}% done"} >> > >> > Something like this ? >> > >> > svg% ri String#% >> >> No, simply >> >> class String >> def decorate >> yield self >> end >> end >> >> martin > > Or ... yes; that's exactly what sprintf is for. > > ary = %w{eight nine ten} > puts "[%s]" % ary.join(",") > n=3 > puts "%s%% done" % (n*100) > > #-> [eight,nine,ten] > #-> 300% done > > The 'attrib example you give is just as simple but I > haven't got the dataset to resolve all the variables. > > > daz > > >