From: Martin DeMello Date: 2003-06-23T00:48:39+09:00 Subject: Re: String#decorate Simon Strandgaard <0bz63fz3m1qt3001@sneakemail.com> wrote: > On Sun, 22 Jun 2003 06:46:00 +0000, Martin DeMello wrote: > >> When chaining methods, it'd be neat to have something that was passed >> in the string and returned a 'decorated' version, e.g. >> >> pp = ary.join(",").decorate {|s| "[#{s}]"} > > I assume you want 'pp' to contain: "(1),(2),(3)" ? No, "[1,2,3]", defining decorate merely as class String def decorate yield self end end > If so then I don't think your example will work: > 1st you join the array into a string > 2nd you decorate each array-element (impossible). No, I want to decorate the *string*, as a prettier way of doing pp = "[" << ary.join(",") << "]" > It works a bit like 'collect' or 'map' > > how about > > title.capitalize.map {|t| "\t -- #{author[t]},\"#{t}\""} No, String#each iterates over its characters. martin