"John Carter" <john.carter / tait.co.nz> schrieb im Newsbeitrag
news:Pine.LNX.4.61.0408110946400.31851 / parore.tait.co.nz...
> On Tue, 10 Aug 2004, Martin DeMello wrote:
>
> > Robert Klemme <bob.news / gmx.net> wrote:
> >>
> >> Hm, sounds to me like it was not general enough to include it in
> >> Enumerable.  Before I see that method I'd prefer to have size and
empty?
> >> in Enumerable.  Just my 0.02 EUR...
> >
> > Can empty? be reliably implemented in terms of each for every
> > enumerable? I can't think of an obvious problem with it, but that
> > doesn't mean there isn't one.
>
> def empty?
>    each do |element|
>      return false
>    end
>    true
> end
>
> def size
>    inject(0) {|n,e| n+=1}
> end

That's basically what i suggested earlier.  Note though that you don't
need the |element| in empty? as well as "n+1" is sufficient in size.

But intermediately I changed my mind (see other thread).

    robert