Brad Phelan wrote:
> Pe?a wrote:
>> From: Logan Capaldo [mailto:logancapaldo / gmail.com] # On 8/13/07, Brad 
>> Phelan <phelan / tttech.ttt> wrote:
>> # > Enumerator.new(s, :scan, /(.)\1*/).map {$&}
>> # What's wrong with s.enum_for(:scan, /(.)\1*/).map { $& } ?
>>
>> somehow i missed the enumerator hack. thank you logan and brad for the 
>> update.
>> kind regards -botp
>>
> 
> Hey cool .. 'enum_for' exactly what I was looking for. I couldn't 
> understand why it didn't exist and it does. Scratch my suggestion
> for 'enum_scan'.
> 
> B

Would it not be clearer if enum_for worked as

s.enum_for.scan(/(.)\1*/).map { $& }

Quickie


require 'enumerator'

module Enumerable
     class Expr
         def initialize( enum )
             @enum = enum
         end

         def method_missing(name, *args)
             @enum.enum_for_old(name, *args)
         end
     end

end

class Object
     alias :enum_for_old :enum_for
     def enum_for
         Enumerable::Expr.new(self)
     end
end


s = "aabbccvvvvfg dddd"
r = s.enum_for.scan(/(.)\1*/).map {$&}
puts r


(To be correct though a full implementation should use the BlankSlate 
class and properly implement the original enum_for interface )

B