From: Joel VanderWerf Date: 2005-03-07T05:06:14+09:00 Subject: Re: Noob:Objects as key in hash Tom Willis wrote: ... > class PointID > attr_reader :x,:y > > def initialize(x,y) > @x = x > @y = y > @x.freeze > @y.freeze > > end > > def hash > return [@x.object_id,@y.object_id].to_s > end > > def ==(other) > return hash == other.hash > end > > def to_s > return hash() > end > > end One approach to this problem that saves some typing (but isn't terribly efficient because it generates garbage arrays): http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/1555