From: Rick DeNatale Date: 2007-11-10T22:50:22+09:00 Subject: Re: equivalent injecting implementations? On 11/9/07, Trans wrote: > Are these strictly equivalent? I get the feeling no, but I haven't > been able to demonstrate it yet. > > def injecting(s) > inject(s) do |k, i| > yield(k, i); k > end > end > > def injecting(res, &block) > ([res]*length).zip(to_a).each(&block) > res > end > > Thanks, > T. I can't see how in general they can be. In which class or module are you defining these? Since you are using inject and each, I'm guessing that it's either Enumerable or some subclass, But then depending on which subclass you don't have a length method so... Perhaps some more context would help. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/