From: Simon Strandgaard <0bz63fz3m1qt3001@...> Date: 2003-06-22T22:28:09+09:00 Subject: Re: String#decorate 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)" ? 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). Instead prefer supplying a block to #join which does the decoration. [1, 2, 3].join(", ") {|s| "(#{s})"} # "(1), (2), (3)" > attrib = title.capitalize.decorate {|t| "\t -- #{author[t]},\"#{t}\""} > (n*100).to_s.decorate {|p| "#{p}% done"} These cases could be useful. > Not quite an RCR (it's trivially implementable anyway) - just wanted > to see what people thought of the idea, and in particular if anyone > had nicer names to suggest. It works a bit like 'collect' or 'map' how about title.capitalize.map {|t| "\t -- #{author[t]},\"#{t}\""} -- Simon Strandgaard