From: James Coglan Date: 2008-09-20T22:32:37+09:00 Subject: Re: [QUIZ] One-Liners Mashup (#177 again) ------=_Part_3073_872517.1221918030599 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline > > Ready? Here goes. First problem... > You should know this pattern well: > > > [:one, "two", 4] * 3 > => [:one, "two", 4, :one, "two", 4, :one, "two", 4] > > Write a single line method on Array that does this instead: > > > [:one, "two", 4].repeat(3) > => [:one, :one, :one, "two", "two", "two", 4, 4, 4] module Enumerable def repeat(n = 1) map { |e| [e] * n }.inject { |a,b| a + b } end end ------=_Part_3073_872517.1221918030599--