That wouldn't be a problem if we simply define Enumerable#last as "The
last value yielded when you call #each".

// Magnus Holm



On Fri, Sep 17, 2010 at 13:32, Urabe Shyouhei <shyouhei / ruby-lang.org> wrote:
> (2010/09/17 20:10), Nikolai Weibull wrote:
>> On Fri, Sep 17, 2010 at 13:00, Urabe Shyouhei <shyouhei / ruby-lang.org> wrote:
>>> (2010/09/17 19:19), Nikolai Weibull wrote:
>>>> Why doesn Enumerable define a #last method that analogous to #first?
>>>
>>> Simplest counterexample is [1].cycle.last
>>
>> I wouldn say that that example counters the validity of havinglast
>> in Enumerable. I mean, sure, there¡Çs obviously no last element in
>> this example, but neither can #all? be answered:
>>
>> [1].cycle.all?{ |i| i == 1 }
>>
>> even though it has an obvious answer.
>
> OK, a bit more complicated example.
>
> require "stringio"
> s = StringIO.new "foobar"
> e = s.enum_for :each_char
> s.seek 6
> e.last # => nil for your definition, but not sure if it should be?
>
> The point is, an Enumerable's last may not exist for various reasons.
>
>