From: Robert Klemme Date: 2004-03-01T23:44:47+09:00 Subject: Re: UnboundMethod#hash apparently broken in 1.8.1 "Tim Sutherland" schrieb im Newsbeitrag news:slrnc43f2p.j1r.timsuth@europa.zone... > In article , David Alan Black wrote: > >Hi -- > > > >"Robert Klemme" writes: > > > >> Hi all, > >> > >> one can't use UnboundMethod as a hash key: > >> > >> irb(main):001:0> class Foo; def bar;end; end > >> => nil > >> irb(main):002:0> Foo.instance_method( :bar ) > >> => # > >> irb(main):003:0> a = Foo.instance_method( :bar ) > >> => # > >> irb(main):004:0> b = Foo.instance_method( :bar ) > >> => # > >> irb(main):005:0> a == b > >> => true > >> irb(main):006:0> b == a > >> => true > >> irb(main):007:0> a.hash == b.hash > >> => false > >> irb(main):008:0> a.id > >> => 135052720 > >> irb(main):009:0> a.hash > >> => 135052720 > >> irb(main):010:0> b.id > >> => 135044800 > >> irb(main):011:0> b.hash > >> => 135044800 > >> > >> UnboundMethod#hash is broken in > >> $ ruby --version > >> ruby 1.8.1 (2003-12-25) [i386-cygwin] > >> > >> Is that fixed in a later version? > > > >I'm not sure why you describe it as broken. Can you explain > >a little further? > > I think he means because "a == b" but "!a.eql?(b)" and "a.hash != b.hash". Exactly. > It's not a bug, just a lack of a feature. I regard it rather as a bug than a lack of a feature - but I'd agree that it's debatable. My point is that you can't use UnboundMethod as hash key because of this although it would make pretty much sense. (See the other thread about attaching meta data to methods and classes) Regards robert