From: Tom Jordan Date: 2006-08-17T00:21:39+09:00 Subject: Re: block equality On 8/15/06, Justin Collins wrote: > > > Marshall T. Vandegrift wrote: > > "Tom Jordan" writes: > > > > > >> 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? > >> > > > > I haven't dived into the code, but I'm pretty sure that (a) promoting > > a block to a Proc via &block in the argument list results in a new > > Proc each time and (b) ruby 1.8 provides no introspection into the > > actual contents of a block. > > > > > > > Yes, it's kind of like asking if two equations or two methods are equal. > On the other hand, you could probably use the SerializeableProc > (developed here: http://rubyquiz.com/quiz38.html), add an equality > method, and then you'd have it. :) Thanks Marshall and Justin. This http://ruby-doc.org/core/classes/Proc.html#M001161 "Return true if prc is the same object as other_proc, or if they are both procs with the same body." led me to believe that Procs would evaluate to equality if they had the same body. So I would have expected that the following: s = lambda { x = 1 } t = lambda { x = 1 } s == t # => true expected, false in reality So my question is; when would the body of Procs ever be the same? 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