From: Simon Strandgaard <0bz63fz3m1qt3001@...>
Date: 2003-06-07T17:30:53+09:00
Subject: Re: [RCR] join block
On Sat, 07 Jun 2003 06:45:13 +0900, Joel VanderWerf wrote:
> Simon Strandgaard wrote:
>>
>> [1, 2, 3].join {|x| "
#{x} | "}
>>
>> => "1 | 2 | 3 | "
> What, you don't like the utter simplicity of the following? ;)
>
> [1, 2, 3].map {|x| "#{x} | "}.join
This is simple.. but when there is 30 lines between the map/join it
becomes hard to maintain. Array#join which takes a block won't break
existing code.
> I guess the intermediate array is point against this, though.
I think it can be solved without intermediate array.. but yes in my
example code i use array.
> Somehow, I would expect Array#join to pass two args to the block, like this:
>
> [1,2,3].join {|x,y| x < y ? " < " : " >= " }
>
> # ==> "1 < 2 < 3"
me don't understand.
--
Simon Strandgaard