RUBY: Substring matcher #algorithm