"David A. Black" <dblack / rubypal.com> wrote in message news:alpine.LFD.2.00.0910300803050.7908 / rubypal.com... > > On Fri, 30 Oct 2009, Bertram Scharpf wrote: >> Am Freitag, 30. Okt 2009, 13:25:05 +0900 schrieb Michael W. Ryder: >>> Michael W. Ryder wrote: >>>> Just Another Victim of the Ambient Morality wrote: >>>>> I'm actually hoping this is an embarrassing question but how do >>>>> you >>>>> get the tail end of a string? All I've figured out is this: >>>>> >>>>> index = 4 >>>>> string[index, string.size - index] >>>>> >>>>> ...but surely there's a better way. >>>>> >>>> You mean like string[-1]? >>> >>> I'm sorry, I missed the part about the index number of characters. Try >>> string[-index, index]. >> >> That's really ugly. You shouldn't have to mention `index' twice. > > I don't think there's anything wrong with it. It works well, and > there's nothing stylistically wrong with using a local variable twice. > If index is a method that does a (re)calculation every time, you'd > want to cache it, but that's not the case in the example. There's nothing wrong with it other than it doesn't work. As others have pointed out, it's: string[-index..-1] However, I'm more concerned with your general attitude about language structure. Even if it did work, you can say the same thing for my original solution: string[index, string.size - index] It works well... except that it uses both index _and_ string variables twice. Am Freitag is right. It would be better if there were some method of getting the tail end of a string by only mentioning the needed parameters once. I'm very surprised that Ruby does not have this level of expressiveness...