From: Robert Klemme Date: 2004-05-02T01:24:01+09:00 Subject: Re: Don't understand hashing... "Michael Neumann" schrieb im Newsbeitrag news:20040501141807.GD794@miya.intranet.ntecs.de... > Hi, > > Don't know why this happens: > > class Lazy > self.methods.reject{|m| m =~ /^__(.*)__$/}.each {|m| > eval "def #{m}(*args, &block) __getobj__.send(:'#{m}', *args, &block) end" > } > > def initialize(&block) > @block = block > end > > def __getobj__ > if @block > @value = @block.call(*@args) > @block = nil > end > return @value > end > > def method_missing(id, *args, &block) > __getobj__.send(id, *args, &block) > end > > def hash > __getobj__.hash > end > end > > id1 = Lazy.new {:Id} > id2 = :Id > > p id1.hash == id2.hash # => true > > h1 = {} > h2 = {} Did you really mean to use two hashes? robert > h1[id1] = "id1" > h2[id2] = "id2" > > p h1[id2] # => nil (expect: "id1") > p h2[id1] # => "id2" > > I would have expected "id1" for h1[id2]. > Can someone enlighten me? > > Thanks. > > Michael > >