Answering to myself ...

On Mon, Jan 15, 2007 at 10:29:11PM +0900, Stefano Zacchiroli wrote:
>     def delete(o)
>       super(o)
>       @arity[o] -= 1
>       @arity.delete o if @arity[o] == 0
>     end

The above is of course wrong, elements get remove before their arity
reach 0.

> => nil                        # aargh, do I need to alias again in
>                               # derived classes? that's too bad ...

Apparently so, alias makes a *copy* of the method :(

Here is a better version:

  require 'set'
  class MultiSet < Set
    def initialize
      super
      @arity = {}
    end
    attr_reader :arity
    def add(o)
      super(o)
      @arity[o] = 0 unless @arity.member? o
      @arity[o] += 1
    end
    def delete(o)
      @arity[o] -= 1
      if @arity[o] == 0
        super(o)
        @arity.delete o
      end
    end
    alias << add
  end

-- 
Stefano Zacchiroli -*- Computer Science PhD student @ Uny Bologna, Italy
zack@{cs.unibo.it,debian.org,bononia.it} -%- http://www.bononia.it/zack/
(15:56:48)  Zack: e la demo dema ?    /\    All one has to do is hit the
(15:57:15)  Bac: no, la demo scema    \/    right keys at the right time