"David Alan Black" <dblack / wobblini.net> schrieb im Newsbeitrag
news:m31xlteqa3.fsf / wobblini.net...
> Hi --
>
> "Robert Klemme" <bob.news / gmx.net> writes:
>
> > "Harry Ohlsen" <harryo / zip.com.au> schrieb im Newsbeitrag
> > news:409CD011.4040905 / zip.com.au...
> > >
> > > How about ...
> > >
> > >   def last5(arr)
> > >      if arr.length < 5
> > >         arr.dup
> > >       else
> > >         arr[-5, 5]
> > >       end
> > >    end
> >
> > Not general enough.  Rather
> >
> > irb(main):001:0> class Array;def last(n);size>=n ? self[-n .. -1] :
> > self;end;end
> > => nil
> > irb(main):002:0> [1,2].last 5
> > => [1, 2]
> > irb(main):003:0> [1,2,3,4,5,6,7].last 5
> > => [3, 4, 5, 6, 7]
>
> Isn't that how Array#last works now?

Oh, I didn't even notice there is Array#last. :-)

    robert