On 5/6/05, Martin DeMello <martindemello / yahoo.com> wrote:
> The recent mention of String#squeeze made me wonder if it would not be a
> good idea to add a #squeeze method to Array (or possibly even to
> Enumerable) as well. Certainly I've needed it at least as often as I've
> needed #uniq
> 
> martin
> 
> 

Well here's a possible implementation:

module Enumerable
        def squeeze(*args)
                raise ArgumentError.new("Provide 0 or 1 arguments") if
args.length > 1
                inject([]) do |a, b|
                        if args.length == 0
                                if b == a.last 
                                        a
                                else
                                        a << b
                                end
                        else
                                if b == a.last && a.last == args[0]
                                        a
                                else
                                        a << b
                                end
                        end
                end
        end
end