Bug #3388: regexp support for start_with? and end_with?
http://redmine.ruby-lang.org/issues/show/3388

Author: Thomas Sawyer
Status: Open, Priority: Normal
ruby -v: 1.9.2dev

ruby-1.9.2-head > "aBcdeFghIj".start_with?(/abc/i)
=> false 

In my implementation of start_with? it is easy enough to utilize #index, which works fine:

  def start_with?(pattern)
    index(pattern) == 0
  end

But #end_with? is more difficult, and I had to use regular expressions.

    def end_with?(suffix)
      suffix = Regexp.escape(suffix) if String===suffix
      /#{suffix}$/.match(self) ? true : false
    end

However, we might get rid of the '? true : false' and return the MatchData, since that could be useful information.


----------------------------------------
http://redmine.ruby-lang.org