Skip to content

Commit

Permalink
Implement String#end_with?
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick committed Apr 19, 2013
1 parent 6785be0 commit 4fd80dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 10 additions & 0 deletions lib-topaz/string.rb
Expand Up @@ -67,6 +67,16 @@ def start_with?(*prefixes)
end
end

def end_with?(*suffixes)
suffixes.any? do |suffix|
next false unless suffix.respond_to?(:to_str)
suffix = suffix.to_str
suflen = suffix.length
next false if suflen > self.length
(-suflen).upto(-1).all? { |index| self[index] == suffix[index] }
end
end

def match(pattern)
return Regexp.new(pattern).match(self)
end
Expand Down
8 changes: 0 additions & 8 deletions spec/tags/core/string/end_with_tags.txt

This file was deleted.

0 comments on commit 4fd80dc

Please sign in to comment.