From: "David A. Black" Date: 2005-05-16T20:51:28+09:00 Subject: Re: determining common characters from start of two strings? --927295978-786337774-1116244267=:24570 Content-Type: MULTIPART/MIXED; BOUNDARY="927295978-786337774-1116244267=:24570" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --927295978-786337774-1116244267=:24570 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi -- On Mon, 16 May 2005, [ISO-8859-1] Brian Schr=F6der wrote: > class String > def lcommon(other) > 0.upto(length) do | i | return i if other[i] !=3D self[i] end > length > end > end You can also use the return value of times to do this: class String def lcommon(other) length.times do |i| return i if other[i] !=3D self[i] end end end (I had been toying with this but using break instead of return, which was giving me problems :-) David --=20 David A. Black dblack@wobblini.net --927295978-786337774-1116244267=:24570-- --927295978-786337774-1116244267=:24570--