From: William James Date: 2006-02-12T18:08:31+09:00 Subject: Re: Getting last character from a string draco draco wrote: > Hello > I'm new to Ruby. I've a simple question. > Is there a more readable way to get last character from string than this > one? : > > x = "text" > last_char = x[x.length-1, x.length-1] "abc"[ -1..-1 ] "abc".slice(-1,1) "abc".slice(-1).chr "abc"[ /.$/ ] "abc".reverse[0,1] "abc".split('').pop class String def last self[-1,1] end end "abc".last