Вам необходимо переопределить #eql?
и метод hash .
Вы можете определить это как:
def hash
id.hash + 32 * desc.hash
end
подробности:
Чтобы увидеть, что называется в Ruby 1.9:
% irb
>> class Logger < BasicObject
>> def initialize(delegate)
>> @delegate = delegate
>> end
>> def method_missing(m,*args,&blk)
>> ::STDOUT.puts [m,args,blk].inspect
>> @delegate.send(m,*args,&blk)
>> end
>> end
=> nil
>> object = Logger.new(Object.new)
[:inspect, [], nil]
=> #<Object:0x000001009a02f0>
>> [object] - [0]
[:hash, [], nil]
[:inspect, [], nil]
=> [#<Object:0x000001009a02f0>]
>> zero = Logger.new(0)
[:inspect, [], nil]
=> 0
>> [zero] - [0]
[:hash, [], nil]
[:eql?, [0], nil]
=> []
То же самое верно для ruby 1.8.7
% irb18
>> class Logger < Object
>> instance_methods.each { |m| undef_method m }
>> def initialize(delegate)
>> @delegate = delegate
>> end
>> def method_missing(m,*args,&blk)
>> ::STDOUT.puts [m,args,blk].inspect
>> @delegate.send(m,*args,&blk)
>> end
>> end
(irb):2: warning: undefining `__send__' may cause serious problem
(irb):2: warning: undefining `__id__' may cause serious problem
=> nil
>> object = Logger.new(Object.new)
[:inspect, [], nil]
=> #<Object:0x100329690>
>> [object] - [0]
[:hash, [], nil]
[:inspect, [], nil]
=> [#<Object:0x100329690>]
>> zero = Logger.new(0)
[:inspect, [], nil]
=> 0
>> [zero] - [0]
[:hash, [], nil]
[:eql?, [0], nil]
=> []