On Nov 13, 2007, at 12:20 AM, furtive.clown / gmail.com wrote:

> On Nov 12, 7:31 pm, Raul Parolari <raulparol... / gmail.com> wrote:
>>
>> But the point that JGII is making about 're' is not that he prefers
>> Regexp literals vs variables! it is that if the regexp variable
>> contained an anchor like \A it does not make a lot of sense to call
>> gsub... because it would at most match once!
>>
>> So while we may not know the exact content of the regexp (eg, it is
>> provided by another component, etc), it makes sense to think that at
>> least we know it is suited to a global replace (if not, what  
>> exactly are
>> we doing? the whole thing loses any sense).
>
> Of course I understand JGII's point, but he does not understand mine.

Careful there.  Let's not turn this into name calling.

> Instead of trying to understand the overall aim, which was the use of
> Object#as, JGII decided to be pedantic about the contents of the
> block.

I remember this going down as:

1.  You showed as() and said you could provide examples of why it's  
so important
2.  I said I didn't get it an would like to see those examples
3.  You showed examples
4.  I said that I felt those examples didn't properly show as() to be  
a must have, for various reasons
5.  It became clear we just disagreed about that

> He wanted to replace the block with concat(), which is simply  
> incorrect.

Can you show how my concat() solution was "incorrect?"  You had code  
like:

 >> (1..3).map { |n| n * 2 } + [4, 5]
=> [2, 4, 6, 4, 5]

I suggested using:

 >> (1..3).map { |n| n * 2 }.concat([4, 5])
=> [2, 4, 6, 4, 5]

They look equivalent to me.

Under the hood concat() is a destructive change to the original Array  
whereas the + operator creates a new Array.  However, since we used  
map() first to generate an Array, that doesn't affect us here.

James Edward Gray II