"Phrogz" <gavin / refinery.com> writes:

>> Following is my hackish attempt to make a String#scan_and_map
>> function that does the above.
>
> OK, that was dumb. On the way to work I realized that the above can far
> more correctly be implemented simply as:
>
> class String
>   def scan_and_map( regexp )
>     results = []
>     scan( regexp ){ |args|
>       results << yield( args )
>     }
>     results
>   end
> end
>
> str = 'foo,bar ,, baz,qux,,,jorb,jing,,,,blat'
> p str.scan_and_map( /(.+?[^,],{2}*)(?:,(?!,)|$)/ ){ |saved,others|
>   saved 
> } 

p str.scan( /(.+?[^,],{2}*)(?:,(?!,)|$)/ ).map{ |saved,others|
  saved 
} 

Trivialized?
-- 
Christian Neukirchen  <chneukirchen / gmail.com>  http://chneukirchen.org