aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew
diff options
context:
space:
mode:
authorJack Nagel2013-07-19 22:31:03 -0500
committerJack Nagel2013-07-19 22:31:07 -0500
commitb1e5f5ee8119782bbd1761181e86546d56d3b53c (patch)
treef46af18baf8d12fb59a65787daad7980bec81190 /Library/Homebrew
parent988316a16d0ab17fca416e051c7c75785642f7e1 (diff)
downloadbrew-b1e5f5ee8119782bbd1761181e86546d56d3b53c.tar.bz2
Fix String#start_with? implementation
It is supposed to accept a variable number of prefixes, and also to check if they are convertible to strings. This matches behavior documented in RubySpec.
Diffstat (limited to 'Library/Homebrew')
-rw-r--r--Library/Homebrew/extend/string.rb12
1 files changed, 7 insertions, 5 deletions
diff --git a/Library/Homebrew/extend/string.rb b/Library/Homebrew/extend/string.rb
index 1b3c1403e..b2a247297 100644
--- a/Library/Homebrew/extend/string.rb
+++ b/Library/Homebrew/extend/string.rb
@@ -15,12 +15,14 @@ class String
# EOS
alias_method :undent_________________________________________________________72, :undent
- unless String.method_defined?(:start_with?)
- def start_with? prefix
- prefix = prefix.to_s
- self[0, prefix.length] == prefix
+ def start_with?(*prefixes)
+ prefixes.any? do |prefix|
+ if prefix.respond_to?(:to_str)
+ prefix = prefix.to_str
+ self[0, prefix.length] == prefix
+ end
end
- end
+ end unless method_defined?(:start_with?)
# String.chomp, but if result is empty: returns nil instead.
# Allows `chuzzle || foo` short-circuits.