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
|
# EOS
|
||||||
alias_method :undent_________________________________________________________72, :undent
|
alias_method :undent_________________________________________________________72, :undent
|
||||||
|
|
||||||
unless String.method_defined?(:start_with?)
|
def start_with?(*prefixes)
|
||||||
def start_with? prefix
|
prefixes.any? do |prefix|
|
||||||
prefix = prefix.to_s
|
if prefix.respond_to?(:to_str)
|
||||||
self[0, prefix.length] == prefix
|
prefix = prefix.to_str
|
||||||
|
self[0, prefix.length] == prefix
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end unless method_defined?(:start_with?)
|
||||||
|
|
||||||
# String.chomp, but if result is empty: returns nil instead.
|
# String.chomp, but if result is empty: returns nil instead.
|
||||||
# Allows `chuzzle || foo` short-circuits.
|
# Allows `chuzzle || foo` short-circuits.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user