From: Tom Jordan Date: 2006-08-16T06:24:23+09:00 Subject: block equality Is there a way to compare two blocks with each other? If you promote a block into a Proc, how would you know that the original block was the same? This is what I want to do (1..10).each do once { puts "Hi Tom"} end I've tried to implement once like this class << self def once(&block) @ids ||= {} block.call unless @ids.key? block.object_id @ids[block.object_id] = :true puts @ids.keys.join(', ') end end I've even tried a varient using == and === def l(&b) @t ||= b puts b == @t puts b === @t @t = b end (1..2).each { l{x=1} } output: true true false false How can you compare two procs that have the same body? Thanks, -- Tom. -- "Nothing will ever be attempted, if all possible objections must first be overcome." - Samuel Johnson "Luck is what happens when preparation meets opportunity." - Seneca