From: Ryan Davis Date: 2007-06-05T02:40:32+09:00 Subject: Re: Getting the last N bytes of a string: On Jun 1, 2007, at 23:14 , Brian Candler wrote: > I think I'll stick with buf[-10,10] || buf. I was just wondering if > I'd > missed something obvious like buf.last(10), after staring at 'ri > String' too > long. you could do that too: >> "blah blah blah".split(//).last(4).join => "blah" or do what you were looking for: >> class String; def last(n=1); self[-n, n] || self; end; end => nil >> "blah".last(10) => "blah" >> "blah blah".last(4) => "blah"