aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/extend/string.rb
diff options
context:
space:
mode:
authorJack Nagel2013-07-19 22:32:56 -0500
committerJack Nagel2013-07-19 22:32:57 -0500
commit8e0158b4d74b3724d31cd284ce362b07f5678d9f (patch)
tree62458514034bcd22d6e6f8d84ccbb724cb7d9703 /Library/Homebrew/extend/string.rb
parentb1e5f5ee8119782bbd1761181e86546d56d3b53c (diff)
downloadbrew-8e0158b4d74b3724d31cd284ce362b07f5678d9f.tar.bz2
Add String#end_with?
I'm tired of not remembering if start_with?/end_with? are portable, so just add them both if they're not defined.
Diffstat (limited to 'Library/Homebrew/extend/string.rb')
-rw-r--r--Library/Homebrew/extend/string.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/Library/Homebrew/extend/string.rb b/Library/Homebrew/extend/string.rb
index b2a247297..7fe47d38e 100644
--- a/Library/Homebrew/extend/string.rb
+++ b/Library/Homebrew/extend/string.rb
@@ -24,6 +24,15 @@ class String
end
end unless method_defined?(:start_with?)
+ def end_with?(*suffixes)
+ suffixes.any? do |suffix|
+ if suffix.respond_to?(:to_str)
+ suffix = suffix.to_str
+ self[-suffix.length, suffix.length] == suffix
+ end
+ end
+ end unless method_defined?(:end_with?)
+
# String.chomp, but if result is empty: returns nil instead.
# Allows `chuzzle || foo` short-circuits.
def chuzzle