From b1e5f5ee8119782bbd1761181e86546d56d3b53c Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Fri, 19 Jul 2013 22:31:03 -0500 Subject: [PATCH] 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. --- Library/Homebrew/extend/string.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/extend/string.rb b/Library/Homebrew/extend/string.rb index 1b3c1403ef..b2a247297b 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.