diff options
| author | Jack Nagel | 2013-07-19 22:31:03 -0500 |
|---|---|---|
| committer | Jack Nagel | 2013-07-19 22:31:07 -0500 |
| commit | b1e5f5ee8119782bbd1761181e86546d56d3b53c (patch) | |
| tree | f46af18baf8d12fb59a65787daad7980bec81190 /Library | |
| parent | 988316a16d0ab17fca416e051c7c75785642f7e1 (diff) | |
| download | brew-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')
| -rw-r--r-- | Library/Homebrew/extend/string.rb | 12 |
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. |
