From: Sean O'Halpin Date: 2005-11-15T00:45:32+09:00 Subject: Re: Comparing Proc Objects? On 11/14/05, Daniel Schierbeck wrote: > What I'm interested in > knowing is how I check whether any supplied block matches the one from > the cached call. I think the only way you're going to get equality with a supplied block is if it is an object, i.e. created with proc or Proc.new or by passing through another method. Every other form is generated on the fly AFAIK. Regards, Sean P.S. This is what I used to test this: require 'pp' @blocks = Hash.new(0) def count_block(&block) @blocks[block] += 1 end def make_block(&block) block end def test_method(x) x + 1 end block = proc {|x| x + 1} block2 = Proc.new do |x| x + 1 end count_block &block count_block &block count_block &block2 count_block &block2 count_block do |x| x + 1 end count_block do |x| x + 1 end count_block { |x| x + 1 } count_block { |x| x + 1 } count_block &make_block { |x| x + 1 } count_block &method(:test_method) count_block &method(:test_method) meth = method(:test_method) count_block &meth count_block &meth meth2 = Proc.new &method(:test_method) count_block &meth2 count_block &meth2 pp @blocks __END__ ---------- OUTPUT ---------- {#=>1, #=>2, #=>2, #=>2, #=>1, #=>1, #=>1, #=>1, #=>1, #=>1, #=>1, #=>1}