From: Robert Klemme Date: 2004-08-11T20:51:16+09:00 Subject: Re: empty? and size in Enumerable "Kristof Bastiaensen" schrieb im Newsbeitrag news:pan.2004.08.11.11.25.43.340597@vleeuwen.org... > > I've changed my mind here: the contract of Enumerable (or of #each if you > > like) is too weak to guarantee a proper implementation of size and empty?. > > The requirements on #each are really very weak and you can't provide a > > proper size and empty? method for each classes using Enumerable. So IMHO > > it's best to leave them out or put them in a separate module. > > > > Kind regards > > > > robert > > You are right. Well, in fact *Matz* was right. I'm just a stupid guy that needed quite a detour to reach this understanding of the matter. Thank you for helping my on this! Once again learnes something new. > While thinking of the best example to support > my argument, I actually came up with an (non esoteric) example > that shows your point. > IO includes enumerable, and reading from an IO will change the IO. Yeah, there are Enumerables that can yield their sequence only once. > For example: > > require 'stringio' > io = StringIO.new < first line > second line > third line > EOS > > io.map unless io.empty > => ["second line\n", "third line\n"] Nice short example that has it all. > So I think that's really the reason why size and empty? is > not included. So finally we reach consensus. :-) Thanks again! robert