From: Bertram Scharpf Date: 2007-06-02T12:57:37+09:00 Subject: Re: Getting the last N bytes of a string: Hi, Am Freitag, 01. Jun 2007, 20:15:54 +0900 schrieb Brian Candler: > 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 > > ? ,From time to time I find myself trying to do something like that. Maybe the best thing was if the String#slice method were defined for using negative lengths but that's probably too late. For my personal use I wrote a litte extension doing exactly that. You can have it if you want. http://www.bertram-scharpf.de/tmp/bs-ruby.tar.gz Inspite of its shortness it's surely buggy. Parameter definition will ever be a matter of taste. Don't try to convince the core developpers there's a neccessity to proffer a solution for this. No chance. Bertram -- Bertram Scharpf Stuttgart, Deutschland/Germany http://www.bertram-scharpf.de