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.
This commit is contained in:
parent
988316a16d
commit
b1e5f5ee81
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user