From: Pit Capitain Date: 2007-03-28T22:23:58+09:00 Subject: Re: String Intersection. A better way Daniel N schrieb: > I have an issue with strings. I want the intesection of two strings but > I'm > not sure how to go about it. I have two cases. > (...) Daniel, if your strings aren't too big, you could try this: class String def intersection_at_start(other) not empty? and other[/#{split(//)*"("}#{")?"*(size-1)}\z/] end def intersection_at_end(other) other.intersection_at_start(self) end def &(other) intersection_at_start(other) or intersection_at_end(other) or "" end end I don't know if this is faster than your original implementation, and it certainly isn't easier to understand, but at least it passes Rob's tests. Regards, Pit