From: Stefan Rusterholz Date: 2007-08-12T19:07:07+09:00 Subject: Re: first and last char Daniel DeLorme wrote: > Stefan Rusterholz wrote: >> Ew, that's awfully complex. You create n new objects from which you >> throw n-1 away again... >> Think of the memory! ;-) >> def first; self[0,1]; end; def last; self[-1,1]; end > > wrong, that's the first and last *bytes*, not characters. > > def first; self[/\A./m]; end > def last; self[/.\z/m]; end > > >> $KCODE='u' > => "u" > >> "日本語".first > => "日" > >> "日本語".last > => "語" > > Daniel You are right, your solution is better. Regards Stefan -- Posted via http://www.ruby-forum.com/.