Hi --

On Fri, 30 Oct 2009, Bertram Scharpf wrote:

> Hi,
>
> 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.


David

-- 
The          Ruby training with D. Black, G. Brown, J.McAnally
Compleat     Jan 22-23, 2010, Tampa, FL
Rubyist      http://www.thecompleatrubyist.com

David A. Black/Ruby Power and Light, LLC (http://www.rubypal.com)