buf.reverse[0,10]?

On 6/1/07, Brian Candler <B.Candler / pobox.com> wrote:
> What's the simplest way to get only the last 10 bytes of a string?
>
>     buf[-10,10]
>
> doesn't work if buf is smaller than 10 bytes, as it returns nil. Is there
> anything simpler than
>
>     buf[-10,10] || buf
>
> ?
>
> Thanks,
>
> Brian.
>
> P.S. To get the *first* 10 bytes of a string is easy: buf[0,10] always
> works, whether or not buf is smaller than 10 bytes)
>
>